Update repository on first run of F-Droid.

This commit is contained in:
Peter Serwylo 2017-02-21 11:25:22 +11:00
parent 09af5402e8
commit 2164a2662a

View File

@ -1,6 +1,7 @@
package org.fdroid.fdroid.views.main; package org.fdroid.fdroid.views.main;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView; import android.support.design.widget.BottomNavigationView;
@ -10,6 +11,8 @@ import android.view.MenuItem;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.Utils;
/** /**
* Main view shown to users upon starting F-Droid. * Main view shown to users upon starting F-Droid.
@ -27,6 +30,8 @@ import org.fdroid.fdroid.R;
*/ */
public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener { public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {
private static final String TAG = "MainActivity";
public static final String EXTRA_VIEW_MY_APPS = "org.fdroid.fdroid.views.main.MainActivity.VIEW_MY_APPS"; public static final String EXTRA_VIEW_MY_APPS = "org.fdroid.fdroid.views.main.MainActivity.VIEW_MY_APPS";
private RecyclerView pager; private RecyclerView pager;
@ -47,6 +52,24 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationV
BottomNavigationView bottomNavigation = (BottomNavigationView) findViewById(R.id.bottom_navigation); BottomNavigationView bottomNavigation = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNavigation.setOnNavigationItemSelectedListener(this); bottomNavigation.setOnNavigationItemSelectedListener(this);
initialRepoUpdateIfRequired();
}
/**
* The first time the app is run, we will have an empty app list. To deal with this, we will
* attempt to update with the default repo. However, if we have tried this at least once, then
* don't try to do it automatically again.
*/
private void initialRepoUpdateIfRequired() {
final String triedEmptyUpdate = "triedEmptyUpdate";
SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
boolean hasTriedEmptyUpdate = prefs.getBoolean(triedEmptyUpdate, false);
if (!hasTriedEmptyUpdate) {
Utils.debugLog(TAG, "We haven't done an update yet. Forcing repo update.");
prefs.edit().putBoolean(triedEmptyUpdate, true).apply();
UpdateService.updateNow(this);
}
} }
@Override @Override