|
@@ -19,7 +19,6 @@
|
|
|
|
|
|
package org.notabug.lifeuser.moviedb.activity;
|
|
package org.notabug.lifeuser.moviedb.activity;
|
|
|
|
|
|
-import android.annotation.SuppressLint;
|
|
|
|
import android.content.ContentValues;
|
|
import android.content.ContentValues;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.content.DialogInterface;
|
|
@@ -72,6 +71,7 @@ public class MainActivity extends BaseActivity {
|
|
private final static int REQUEST_CODE_ASK_PERMISSIONS_IMPORT = 124;
|
|
private final static int REQUEST_CODE_ASK_PERMISSIONS_IMPORT = 124;
|
|
private final static String LIVE_SEARCH_PREFERENCE = "key_live_search";
|
|
private final static String LIVE_SEARCH_PREFERENCE = "key_live_search";
|
|
private final static String REWATCHED_FIELD_CHANGE_PREFERENCE = "key_rewatched_field_change";
|
|
private final static String REWATCHED_FIELD_CHANGE_PREFERENCE = "key_rewatched_field_change";
|
|
|
|
+ private final static String PREVIOUS_APPLICATION_VERSION_PREFERENCE = "key_application_version";
|
|
/**
|
|
/**
|
|
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
|
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
|
* fragments for each of the sections. We use a
|
|
* fragments for each of the sections. We use a
|
|
@@ -86,6 +86,7 @@ public class MainActivity extends BaseActivity {
|
|
private boolean isSearchOpened = false;
|
|
private boolean isSearchOpened = false;
|
|
private EditText editSearch;
|
|
private EditText editSearch;
|
|
private SharedPreferences preferences;
|
|
private SharedPreferences preferences;
|
|
|
|
+ ViewPager mViewPager;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -106,17 +107,24 @@ public class MainActivity extends BaseActivity {
|
|
/*
|
|
/*
|
|
The {@link ViewPager} that will host the section contents.
|
|
The {@link ViewPager} that will host the section contents.
|
|
*/
|
|
*/
|
|
- ViewPager mViewPager = (ViewPager) findViewById(R.id.container);
|
|
|
|
|
|
+ mViewPager = (ViewPager) findViewById(R.id.container);
|
|
mViewPager.setAdapter(mSectionsPagerAdapter);
|
|
mViewPager.setAdapter(mSectionsPagerAdapter);
|
|
|
|
|
|
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
|
|
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
|
|
tabLayout.setupWithViewPager(mViewPager);
|
|
tabLayout.setupWithViewPager(mViewPager);
|
|
|
|
|
|
preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
+ int versionNumber;
|
|
|
|
+ try {
|
|
|
|
+ versionNumber = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
|
|
|
|
+ } catch (PackageManager.NameNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ versionNumber = -1;
|
|
|
|
+ }
|
|
|
|
|
|
// The rewatched field has changed to watched, notify users that make use of the database
|
|
// The rewatched field has changed to watched, notify users that make use of the database
|
|
// of this change and also tell them that the value is automatically increased by one.
|
|
// of this change and also tell them that the value is automatically increased by one.
|
|
- if (!preferences.getBoolean(REWATCHED_FIELD_CHANGE_PREFERENCE, false)) {
|
|
|
|
|
|
+ if (!preferences.getBoolean(REWATCHED_FIELD_CHANGE_PREFERENCE, false) && preferences.getInt(PREVIOUS_APPLICATION_VERSION_PREFERENCE, versionNumber) < 190) {
|
|
File dbFile = getDatabasePath(MovieDatabaseHelper.getDatabaseFileName());
|
|
File dbFile = getDatabasePath(MovieDatabaseHelper.getDatabaseFileName());
|
|
|
|
|
|
// If there is a database.
|
|
// If there is a database.
|
|
@@ -174,6 +182,10 @@ public class MainActivity extends BaseActivity {
|
|
preferences.edit().putBoolean(REWATCHED_FIELD_CHANGE_PREFERENCE, true).apply();
|
|
preferences.edit().putBoolean(REWATCHED_FIELD_CHANGE_PREFERENCE, true).apply();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (versionNumber != -1) {
|
|
|
|
+ preferences.edit().putInt(PREVIOUS_APPLICATION_VERSION_PREFERENCE, versionNumber).commit();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -223,8 +235,10 @@ public class MainActivity extends BaseActivity {
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
// Needs to be explicitly called otherwise
|
|
// Needs to be explicitly called otherwise
|
|
// onActivityResult won't trigger in the Fragment.
|
|
// onActivityResult won't trigger in the Fragment.
|
|
- Fragment mCurrentFragment = getSupportFragmentManager().getFragments()
|
|
|
|
- .get(mSectionsPagerAdapter.getCurrentFragmentPosition());
|
|
|
|
|
|
+
|
|
|
|
+ // This is a hack
|
|
|
|
+ Fragment mCurrentFragment = getSupportFragmentManager()
|
|
|
|
+ .findFragmentByTag("android:switcher:" + R.id.container + ":" + mViewPager.getCurrentItem());
|
|
mCurrentFragment.onActivityResult(requestCode, resultCode, data);
|
|
mCurrentFragment.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
@@ -359,8 +373,9 @@ public class MainActivity extends BaseActivity {
|
|
* @param query the search query.
|
|
* @param query the search query.
|
|
*/
|
|
*/
|
|
private void searchInFragment(String query) {
|
|
private void searchInFragment(String query) {
|
|
- @SuppressLint("RestrictedApi") Fragment mCurrentFragment = getSupportFragmentManager()
|
|
|
|
- .getFragments().get(mSectionsPagerAdapter.getCurrentFragmentPosition());
|
|
|
|
|
|
+ // This is a hack
|
|
|
|
+ Fragment mCurrentFragment = getSupportFragmentManager()
|
|
|
|
+ .findFragmentByTag("android:switcher:" + R.id.container + ":" + mViewPager.getCurrentItem());
|
|
|
|
|
|
if (mCurrentFragment != null) {
|
|
if (mCurrentFragment != null) {
|
|
if (mCurrentFragment instanceof ShowFragment) {
|
|
if (mCurrentFragment instanceof ShowFragment) {
|
|
@@ -381,8 +396,9 @@ public class MainActivity extends BaseActivity {
|
|
* Cancel the searching process in the fragment.
|
|
* Cancel the searching process in the fragment.
|
|
*/
|
|
*/
|
|
private void cancelSearchInFragment() {
|
|
private void cancelSearchInFragment() {
|
|
- @SuppressLint("RestrictedApi") Fragment mCurrentFragment = getSupportFragmentManager()
|
|
|
|
- .getFragments().get(mSectionsPagerAdapter.getCurrentFragmentPosition());
|
|
|
|
|
|
+ // This is a hack
|
|
|
|
+ Fragment mCurrentFragment = getSupportFragmentManager()
|
|
|
|
+ .findFragmentByTag("android:switcher:" + R.id.container + ":" + mViewPager.getCurrentItem());
|
|
|
|
|
|
if (mCurrentFragment != null) {
|
|
if (mCurrentFragment != null) {
|
|
if (mCurrentFragment instanceof ShowFragment) {
|
|
if (mCurrentFragment instanceof ShowFragment) {
|