diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 72b99fbc..245e6ada 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -113,11 +113,12 @@ android:theme="@style/AppTheme.NoActionBar"> + android:value=".activities.upload.UploadActivity" /> { + //Session data update + sessionManager.guestLogin(); + + //Go to main + Intent intent = new Intent(LoginActivity.this, MainActivity.class); + startActivity(intent); + finish(); + overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out); }); } @Override public void onBackPressed() { - // Disable going back to the MainActivity - moveTaskToBack(true); + super.onBackPressed(); if (loginTask != null && loginTask.getStatus() == AsyncTask.Status.RUNNING) { loginTask.cancel(true); } + if(!isTaskRoot()) + overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out); } private void onLoginFailed() { diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java index 101dce1b..7309090a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java @@ -32,8 +32,6 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared private static final String SELECTED_NOTIFICATIONS_SOUND = "pref_notifications_select_sound_key"; private static final String POSTING_CATEGORY = "pref_category_posting_key"; private static final String UPLOADING_CATEGORY = "pref_category_uploading_key"; - public static final String PRIVACY_CRASHLYTICS_ENABLE_KEY = "pref_privacy_crashlytics_enable_key"; - public static final String PRIVACY_ANALYTICS_ENABLE_KEY = "pref_privacy_analytics_enable_key"; //SharedPreferences keys private static final int REQUEST_CODE_ALERT_RINGTONE = 2; diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 6aa08cba..d182adf7 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -35,8 +35,6 @@ import com.mikepenz.materialdrawer.Drawer; import com.mikepenz.materialdrawer.DrawerBuilder; import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import com.mikepenz.materialdrawer.model.ProfileDrawerItem; -import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; -import com.mikepenz.materialdrawer.model.interfaces.IProfile; import java.io.File; import java.util.ArrayList; @@ -329,53 +327,53 @@ public abstract class BaseActivity extends AppCompatActivity { .withDrawerWidthDp((int) BaseApplication.getInstance().getDpWidth() / 2) .withSliderBackgroundColor(ContextCompat.getColor(this, R.color.primary_light)) .withAccountHeader(accountHeader) - .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { - @Override - public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { - if (drawerItem.equals(HOME_ID)) { - if (!(BaseActivity.this instanceof MainActivity)) { - Intent intent = new Intent(BaseActivity.this, MainActivity.class); - startActivity(intent); - } - } else if (drawerItem.equals(DOWNLOADS_ID)) { - if (!(BaseActivity.this instanceof DownloadsActivity)) { - Intent intent = new Intent(BaseActivity.this, DownloadsActivity.class); - Bundle extras = new Bundle(); - extras.putString(BUNDLE_DOWNLOADS_URL, ""); - extras.putString(BUNDLE_DOWNLOADS_TITLE, null); - intent.putExtras(extras); - startActivity(intent); - } - } else if (drawerItem.equals(UPLOAD_ID)) { - if (!(BaseActivity.this instanceof UploadActivity)) { - Intent intent = new Intent(BaseActivity.this, UploadActivity.class); - startActivity(intent); - } - } else if (drawerItem.equals(BOOKMARKS_ID)) { - if (!(BaseActivity.this instanceof BookmarkActivity)) { - Intent intent = new Intent(BaseActivity.this, BookmarkActivity.class); - startActivity(intent); - } - } else if (drawerItem.equals(LOG_ID)) { - if (!sessionManager.isLoggedIn()) //When logged out or if user is guest - startLoginActivity(); - else - new LogoutTask().execute(); - } else if (drawerItem.equals(ABOUT_ID)) { - if (!(BaseActivity.this instanceof AboutActivity)) { - Intent intent = new Intent(BaseActivity.this, AboutActivity.class); - startActivity(intent); - } - } else if (drawerItem.equals(SETTINGS_ID)) { - if (!(BaseActivity.this instanceof SettingsActivity)) { - Intent intent = new Intent(BaseActivity.this, SettingsActivity.class); - startActivity(intent); - } + .withOnDrawerItemClickListener((view, position, drawerItem) -> { + if (drawerItem.equals(HOME_ID)) { + if (!(BaseActivity.this instanceof MainActivity)) { + Intent intent = new Intent(BaseActivity.this, MainActivity.class); + startActivity(intent); + } + } else if (drawerItem.equals(DOWNLOADS_ID)) { + if (!(BaseActivity.this instanceof DownloadsActivity)) { + Intent intent = new Intent(BaseActivity.this, DownloadsActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_DOWNLOADS_URL, ""); + extras.putString(BUNDLE_DOWNLOADS_TITLE, null); + intent.putExtras(extras); + startActivity(intent); + } + } else if (drawerItem.equals(UPLOAD_ID)) { + if (!(BaseActivity.this instanceof UploadActivity)) { + Intent intent = new Intent(BaseActivity.this, UploadActivity.class); + startActivity(intent); + } + } else if (drawerItem.equals(BOOKMARKS_ID)) { + if (!(BaseActivity.this instanceof BookmarkActivity)) { + Intent intent = new Intent(BaseActivity.this, BookmarkActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(intent); + } + } else if (drawerItem.equals(LOG_ID)) { + if (!sessionManager.isLoggedIn()) //When logged out or if user is guest + startLoginActivity(); + else + new LogoutTask().execute(); + } else if (drawerItem.equals(ABOUT_ID)) { + if (!(BaseActivity.this instanceof AboutActivity)) { + Intent intent = new Intent(BaseActivity.this, AboutActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(intent); + } + } else if (drawerItem.equals(SETTINGS_ID)) { + if (!(BaseActivity.this instanceof SettingsActivity)) { + Intent intent = new Intent(BaseActivity.this, SettingsActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(intent); } - - drawer.closeDrawer(); - return true; } + + drawer.closeDrawer(); + return true; }); if (sessionManager.isLoggedIn()) @@ -388,12 +386,9 @@ public abstract class BaseActivity extends AppCompatActivity { if (!(BaseActivity.this instanceof MainActivity)) drawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false); - drawer.setOnDrawerNavigationListener(new Drawer.OnDrawerNavigationListener() { - @Override - public boolean onNavigationClickListener(View clickedView) { - onBackPressed(); - return true; - } + drawer.setOnDrawerNavigationListener(clickedView -> { + onBackPressed(); + return true; }); } @@ -696,36 +691,25 @@ public abstract class BaseActivity extends AppCompatActivity { Button cancelButton = view.findViewById(R.id.cancel); Button openButton = view.findViewById(R.id.open); Button downloadButton = view.findViewById(R.id.download); - cancelButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - dialog.dismiss(); + cancelButton.setOnClickListener(v -> dialog.dismiss()); + openButton.setOnClickListener(v -> { + dialog.dismiss(); + try { + String fileName = thmmyFile.getFilename(); + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION); + Uri fileUri = FileProvider.getUriForFile(getApplicationContext(), getPackageName() + ".provider", new File(SAVE_DIR, fileName)); + intent.setDataAndType(fileUri, getMimeType(fileName)); + BaseActivity.this.startActivity(intent); + } catch (Exception e) { + Timber.e(e, "Couldn't open downloaded file..."); + Toast.makeText(getBaseContext(), "Couldn't open file...", Toast.LENGTH_SHORT).show(); } - }); - openButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - dialog.dismiss(); - try { - String fileName = thmmyFile.getFilename(); - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION); - Uri fileUri = FileProvider.getUriForFile(getApplicationContext(), getPackageName() + ".provider", new File(SAVE_DIR, fileName)); - intent.setDataAndType(fileUri, getMimeType(fileName)); - BaseActivity.this.startActivity(intent); - } catch (Exception e) { - Timber.e(e, "Couldn't open downloaded file..."); - Toast.makeText(getBaseContext(), "Couldn't open file...", Toast.LENGTH_SHORT).show(); - } - } }); - downloadButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - dialog.dismiss(); - DownloadHelper.enqueueDownload(thmmyFile); - } + downloadButton.setOnClickListener(v -> { + dialog.dismiss(); + DownloadHelper.enqueueDownload(thmmyFile); }); dialog.show(); } @@ -738,7 +722,6 @@ public abstract class BaseActivity extends AppCompatActivity { private void startLoginActivity(){ Intent intent = new Intent(BaseActivity.this, LoginActivity.class); startActivity(intent); - finish(); overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); } }