Skip to content

Commit

Permalink
Logout functionality commit
Browse files Browse the repository at this point in the history
Implemented logout function, which deletes the credentials from the sd
card and restart from the sign in page.
  • Loading branch information
Carl26 committed Feb 21, 2017
1 parent c92f331 commit 18c7233
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
Expand All @@ -17,6 +18,7 @@

import org.example.team_pigeon.movie_pigeon.models.Movie;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

Expand All @@ -31,6 +33,8 @@ public class MeFragment extends Fragment {
private Gson gson = new Gson();
private MyTask myTask;
private ArrayList<Movie> movieList;
private File credential;

public MeFragment() {
}

Expand All @@ -53,9 +57,36 @@ public void onClick(View v) {
myTask.execute("bookmark");
}
});

logoutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e(TAG, "Logout button pressed");
loggingOut();
}
});
return view;
}

private void loggingOut() {
Intent loadStartActivity = new Intent(getActivity(), StartActivity.class);
credential = new File(Environment.getExternalStorageDirectory() + "/MoviePigeon/Signin/credential");
if (credential.exists()) {
Log.e(TAG, "Deleting existing credentials");
credential.delete();
}

if (!credential.exists()) {
Log.e(TAG, "Starting sign in activity");
getActivity().startActivity(loadStartActivity);
Log.e(TAG, "Finishing current activity");
getActivity().finish();
} else {
Log.e(TAG, "Failed to delete credential");
Toast.makeText(getContext(), "Failed to logout", Toast.LENGTH_SHORT).show();
}
}

private void bindViews(View view){
myBookmarksButton = (Button)view.findViewById(R.id.button_my_bookmarks);
myRatingsButton = (Button)view.findViewById(R.id.button_my_rating);
Expand Down

0 comments on commit 18c7233

Please sign in to comment.