Speed up starting
This commit is contained in:
parent
49acc3f977
commit
990fad0e0d
|
@ -59,6 +59,7 @@ import androidx.appcompat.widget.PopupMenu;
|
||||||
import androidx.appcompat.widget.SearchView;
|
import androidx.appcompat.widget.SearchView;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
@ -197,6 +198,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
MASTALAB
|
MASTALAB
|
||||||
}
|
}
|
||||||
public static iconLauncher mLauncher = iconLauncher.BUBBLES;
|
public static iconLauncher mLauncher = iconLauncher.BUBBLES;
|
||||||
|
private Account account;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -208,7 +210,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
||||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
PackageManager pm = getPackageManager();
|
PackageManager pm = getPackageManager();
|
||||||
try {
|
try {
|
||||||
|
@ -438,7 +440,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
|
|
||||||
main_app_container = findViewById(R.id.main_app_container);
|
main_app_container = findViewById(R.id.main_app_container);
|
||||||
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||||
new SyncTimelinesAsyncTask(BaseMainActivity.this, 0, BaseMainActivity.this).execute();
|
new SyncTimelinesAsyncTask(BaseMainActivity.this, 0, Helper.canFetchList(getApplicationContext(), account), BaseMainActivity.this).execute();
|
||||||
|
|
||||||
} else if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
|
} else if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
|
||||||
TabLayout.Tab pTabsub = tabLayout.newTab();
|
TabLayout.Tab pTabsub = tabLayout.newTab();
|
||||||
|
@ -809,7 +811,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
int position = 0;
|
int position = 0;
|
||||||
if (tabLayout != null)
|
if (tabLayout != null)
|
||||||
position = tabLayout.getSelectedTabPosition();
|
position = tabLayout.getSelectedTabPosition();
|
||||||
new SyncTimelinesAsyncTask(BaseMainActivity.this, position, BaseMainActivity.this).execute();
|
new SyncTimelinesAsyncTask(BaseMainActivity.this, position, true,BaseMainActivity.this).execute();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(hidde_menu, new IntentFilter(Helper.RECEIVE_HIDE_ITEM));
|
LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(hidde_menu, new IntentFilter(Helper.RECEIVE_HIDE_ITEM));
|
||||||
|
@ -1543,12 +1545,13 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
} else if (extras.getInt(Helper.INTENT_ACTION) == Helper.REDRAW_MENU) {
|
} else if (extras.getInt(Helper.INTENT_ACTION) == Helper.REDRAW_MENU) {
|
||||||
Helper.hideMenuItem(BaseMainActivity.this, navigationView.getMenu());
|
Helper.hideMenuItem(BaseMainActivity.this, navigationView.getMenu());
|
||||||
} else if (extras.getInt(Helper.INTENT_ACTION) == Helper.SEARCH_TAG) {
|
} else if (extras.getInt(Helper.INTENT_ACTION) == Helper.SEARCH_TAG) {
|
||||||
new SyncTimelinesAsyncTask(BaseMainActivity.this, -1, BaseMainActivity.this).execute();
|
new SyncTimelinesAsyncTask(BaseMainActivity.this, -1, false,BaseMainActivity.this).execute();
|
||||||
} else if (extras.getInt(Helper.INTENT_ACTION) == Helper.REFRESH_TIMELINE) {
|
} else if (extras.getInt(Helper.INTENT_ACTION) == Helper.REFRESH_TIMELINE) {
|
||||||
int position = 0;
|
int position = 0;
|
||||||
|
boolean refreshList = extras.getBoolean(Helper.REFRESH_LIST_TIMELINE, false);
|
||||||
if (tabLayout != null)
|
if (tabLayout != null)
|
||||||
position = tabLayout.getSelectedTabPosition();
|
position = tabLayout.getSelectedTabPosition();
|
||||||
new SyncTimelinesAsyncTask(BaseMainActivity.this, position, BaseMainActivity.this).execute();
|
new SyncTimelinesAsyncTask(BaseMainActivity.this, position, refreshList,BaseMainActivity.this).execute();
|
||||||
} else if (extras.getInt(Helper.INTENT_ACTION) == Helper.SEARCH_REMOTE) {
|
} else if (extras.getInt(Helper.INTENT_ACTION) == Helper.SEARCH_REMOTE) {
|
||||||
String url = extras.getString(Helper.SEARCH_URL);
|
String url = extras.getString(Helper.SEARCH_URL);
|
||||||
intent.replaceExtras(new Bundle());
|
intent.replaceExtras(new Bundle());
|
||||||
|
|
|
@ -98,6 +98,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
|
||||||
private String oldSearch;
|
private String oldSearch;
|
||||||
private int theme;
|
private int theme;
|
||||||
private String instance;
|
private String instance;
|
||||||
|
private boolean refresh_list;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -128,7 +129,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
|
||||||
style = R.style.Dialog;
|
style = R.style.Dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refresh_list = false;
|
||||||
if (getSupportActionBar() != null)
|
if (getSupportActionBar() != null)
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
|
@ -404,6 +405,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
|
||||||
timeline = manageTimelines;
|
timeline = manageTimelines;
|
||||||
new ManageListsAsyncTask(getApplicationContext(), ManageListsAsyncTask.action.DELETE_LIST, null, null, manageTimelines.getListTimeline().getId(), null, ReorderTimelinesActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
new ManageListsAsyncTask(getApplicationContext(), ManageListsAsyncTask.action.DELETE_LIST, null, null, manageTimelines.getListTimeline().getId(), null, ReorderTimelinesActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
new TimelinesDAO(getApplicationContext(), db).remove(timeline);
|
new TimelinesDAO(getApplicationContext(), db).remove(timeline);
|
||||||
|
refresh_list = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
updated = true;
|
updated = true;
|
||||||
|
@ -428,6 +430,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
|
||||||
if (updated) {
|
if (updated) {
|
||||||
Intent intent = new Intent(getBaseContext(), MainActivity.class);
|
Intent intent = new Intent(getBaseContext(), MainActivity.class);
|
||||||
intent.putExtra(Helper.INTENT_ACTION, Helper.REFRESH_TIMELINE);
|
intent.putExtra(Helper.INTENT_ACTION, Helper.REFRESH_TIMELINE);
|
||||||
|
intent.putExtra(Helper.REFRESH_LIST_TIMELINE, refresh_list);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
updated = false;
|
updated = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,16 +15,19 @@
|
||||||
package app.fedilab.android.asynctasks;
|
package app.fedilab.android.asynctasks;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import app.fedilab.android.client.API;
|
import app.fedilab.android.client.API;
|
||||||
import app.fedilab.android.client.APIResponse;
|
import app.fedilab.android.client.APIResponse;
|
||||||
|
import app.fedilab.android.client.Entities.Account;
|
||||||
import app.fedilab.android.client.Entities.ManageTimelines;
|
import app.fedilab.android.client.Entities.ManageTimelines;
|
||||||
import app.fedilab.android.client.Entities.RemoteInstance;
|
import app.fedilab.android.client.Entities.RemoteInstance;
|
||||||
import app.fedilab.android.client.Entities.TagTimeline;
|
import app.fedilab.android.client.Entities.TagTimeline;
|
||||||
|
@ -32,7 +35,6 @@ import app.fedilab.android.helper.Helper;
|
||||||
import app.fedilab.android.sqlite.InstancesDAO;
|
import app.fedilab.android.sqlite.InstancesDAO;
|
||||||
import app.fedilab.android.sqlite.SearchDAO;
|
import app.fedilab.android.sqlite.SearchDAO;
|
||||||
import app.fedilab.android.sqlite.Sqlite;
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
import app.fedilab.android.sqlite.TimelineCacheDAO;
|
|
||||||
import app.fedilab.android.sqlite.TimelinesDAO;
|
import app.fedilab.android.sqlite.TimelinesDAO;
|
||||||
import app.fedilab.android.activities.MainActivity;
|
import app.fedilab.android.activities.MainActivity;
|
||||||
import app.fedilab.android.interfaces.OnSyncTimelineInterface;
|
import app.fedilab.android.interfaces.OnSyncTimelineInterface;
|
||||||
|
@ -50,11 +52,15 @@ public class SyncTimelinesAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
private int position;
|
private int position;
|
||||||
private WeakReference<Context> contextReference;
|
private WeakReference<Context> contextReference;
|
||||||
private List<ManageTimelines> manageTimelines;
|
private List<ManageTimelines> manageTimelines;
|
||||||
|
private boolean syncLists;
|
||||||
|
|
||||||
public SyncTimelinesAsyncTask(Context context, int position, OnSyncTimelineInterface onSyncTimelineInterface) {
|
|
||||||
|
public SyncTimelinesAsyncTask(Context context, int position, boolean syncLists, OnSyncTimelineInterface onSyncTimelineInterface) {
|
||||||
this.contextReference = new WeakReference<>(context);
|
this.contextReference = new WeakReference<>(context);
|
||||||
this.listener = onSyncTimelineInterface;
|
this.listener = onSyncTimelineInterface;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
this.syncLists = syncLists;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,88 +251,97 @@ public class SyncTimelinesAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
APIResponse apiResponse;
|
|
||||||
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
if( this.syncLists ) {
|
||||||
List<app.fedilab.android.client.Entities.List> listsAPI = null;
|
APIResponse apiResponse;
|
||||||
try {
|
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||||
apiResponse = new API(contextReference.get()).getLists();
|
List<app.fedilab.android.client.Entities.List> listsAPI;
|
||||||
listsAPI = apiResponse.getLists();
|
try {
|
||||||
//Check potential duplicated lists in db
|
apiResponse = new API(contextReference.get()).getLists();
|
||||||
List<ManageTimelines> duplicated_id = new ArrayList<>();
|
listsAPI = apiResponse.getLists();
|
||||||
List<String> present_id = new ArrayList<>();
|
//Check potential duplicated lists in db
|
||||||
for (ManageTimelines manageTimeline : manageTimelines) {
|
List<ManageTimelines> duplicated_id = new ArrayList<>();
|
||||||
if (manageTimeline.getListTimeline() == null)
|
List<String> present_id = new ArrayList<>();
|
||||||
continue;
|
for (ManageTimelines manageTimeline : manageTimelines) {
|
||||||
if (!present_id.contains(manageTimeline.getListTimeline().getId())) {
|
if (manageTimeline.getListTimeline() == null)
|
||||||
present_id.add(manageTimeline.getListTimeline().getId());
|
|
||||||
} else {
|
|
||||||
duplicated_id.add(manageTimeline);
|
|
||||||
new TimelinesDAO(contextReference.get(), db).remove(manageTimeline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
manageTimelines.removeAll(duplicated_id);
|
|
||||||
if (listsAPI != null && listsAPI.size() > 0) {
|
|
||||||
//Loop through results
|
|
||||||
for (app.fedilab.android.client.Entities.List list : listsAPI) {
|
|
||||||
boolean isInDb = false;
|
|
||||||
ManageTimelines timelines_tmp = null;
|
|
||||||
for (ManageTimelines manageTimeline : manageTimelines) {
|
|
||||||
if (manageTimeline.getListTimeline() == null)
|
|
||||||
continue;
|
|
||||||
if (manageTimeline.getListTimeline().getId().equals(list.getId())) {
|
|
||||||
isInDb = true;
|
|
||||||
timelines_tmp = manageTimeline;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//The current list is not registred in the database
|
|
||||||
if (!isInDb) {
|
|
||||||
ManageTimelines manageTL = new ManageTimelines();
|
|
||||||
manageTL.setListTimeline(list);
|
|
||||||
manageTL.setDisplayed(true);
|
|
||||||
manageTL.setType(ManageTimelines.Type.LIST);
|
|
||||||
manageTL.setPosition(manageTimelines.size());
|
|
||||||
new TimelinesDAO(contextReference.get(), db).insert(manageTL);
|
|
||||||
manageTimelines.add(manageTL);
|
|
||||||
} else {
|
|
||||||
//Update list
|
|
||||||
timelines_tmp.setListTimeline(list);
|
|
||||||
new TimelinesDAO(contextReference.get(), db).update(timelines_tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ArrayList<ManageTimelines> manageTimelinesToRemove = new ArrayList<>();
|
|
||||||
for (ManageTimelines dbtTimelines : manageTimelines) {
|
|
||||||
if (dbtTimelines.getListTimeline() == null)
|
|
||||||
continue;
|
continue;
|
||||||
boolean shouldBeRemoved = true;
|
if (!present_id.contains(manageTimeline.getListTimeline().getId())) {
|
||||||
|
present_id.add(manageTimeline.getListTimeline().getId());
|
||||||
|
} else {
|
||||||
|
duplicated_id.add(manageTimeline);
|
||||||
|
new TimelinesDAO(contextReference.get(), db).remove(manageTimeline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
manageTimelines.removeAll(duplicated_id);
|
||||||
|
if (listsAPI != null && listsAPI.size() > 0) {
|
||||||
|
//Loop through results
|
||||||
for (app.fedilab.android.client.Entities.List list : listsAPI) {
|
for (app.fedilab.android.client.Entities.List list : listsAPI) {
|
||||||
if (list.getId().equals(dbtTimelines.getListTimeline().getId())) {
|
boolean isInDb = false;
|
||||||
shouldBeRemoved = false;
|
ManageTimelines timelines_tmp = null;
|
||||||
|
for (ManageTimelines manageTimeline : manageTimelines) {
|
||||||
|
if (manageTimeline.getListTimeline() == null)
|
||||||
|
continue;
|
||||||
|
if (manageTimeline.getListTimeline().getId().equals(list.getId())) {
|
||||||
|
isInDb = true;
|
||||||
|
timelines_tmp = manageTimeline;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//The current list is not registred in the database
|
||||||
|
if (!isInDb) {
|
||||||
|
ManageTimelines manageTL = new ManageTimelines();
|
||||||
|
manageTL.setListTimeline(list);
|
||||||
|
manageTL.setDisplayed(true);
|
||||||
|
manageTL.setType(ManageTimelines.Type.LIST);
|
||||||
|
manageTL.setPosition(manageTimelines.size());
|
||||||
|
new TimelinesDAO(contextReference.get(), db).insert(manageTL);
|
||||||
|
manageTimelines.add(manageTL);
|
||||||
|
} else {
|
||||||
|
//Update list
|
||||||
|
timelines_tmp.setListTimeline(list);
|
||||||
|
new TimelinesDAO(contextReference.get(), db).update(timelines_tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (shouldBeRemoved) {
|
ArrayList<ManageTimelines> manageTimelinesToRemove = new ArrayList<>();
|
||||||
new TimelinesDAO(contextReference.get(), db).remove(dbtTimelines);
|
for (ManageTimelines dbtTimelines : manageTimelines) {
|
||||||
manageTimelinesToRemove.add(dbtTimelines);
|
if (dbtTimelines.getListTimeline() == null)
|
||||||
}
|
|
||||||
}
|
|
||||||
if (manageTimelinesToRemove.size() > 0) {
|
|
||||||
manageTimelines.removeAll(manageTimelinesToRemove);
|
|
||||||
}
|
|
||||||
} else { //No lists, all are removed if exist in db
|
|
||||||
ArrayList<ManageTimelines> manageTimelinesToRemove = new ArrayList<>();
|
|
||||||
if (apiResponse.getError() == null) { //Only done if there is no errors when fetching lists
|
|
||||||
for (ManageTimelines manageTimelines : manageTimelines) {
|
|
||||||
if (manageTimelines.getListTimeline() == null)
|
|
||||||
continue;
|
continue;
|
||||||
new TimelinesDAO(contextReference.get(), db).remove(manageTimelines);
|
boolean shouldBeRemoved = true;
|
||||||
manageTimelinesToRemove.add(manageTimelines);
|
for (app.fedilab.android.client.Entities.List list : listsAPI) {
|
||||||
|
if (list.getId().equals(dbtTimelines.getListTimeline().getId())) {
|
||||||
|
shouldBeRemoved = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (shouldBeRemoved) {
|
||||||
|
new TimelinesDAO(contextReference.get(), db).remove(dbtTimelines);
|
||||||
|
manageTimelinesToRemove.add(dbtTimelines);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (manageTimelinesToRemove.size() > 0) {
|
if (manageTimelinesToRemove.size() > 0) {
|
||||||
manageTimelines.removeAll(manageTimelinesToRemove);
|
manageTimelines.removeAll(manageTimelinesToRemove);
|
||||||
}
|
}
|
||||||
|
} else { //No lists, all are removed if exist in db
|
||||||
|
ArrayList<ManageTimelines> manageTimelinesToRemove = new ArrayList<>();
|
||||||
|
if (apiResponse.getError() == null) { //Only done if there is no errors when fetching lists
|
||||||
|
for (ManageTimelines manageTimelines : manageTimelines) {
|
||||||
|
if (manageTimelines.getListTimeline() == null)
|
||||||
|
continue;
|
||||||
|
new TimelinesDAO(contextReference.get(), db).remove(manageTimelines);
|
||||||
|
manageTimelinesToRemove.add(manageTimelines);
|
||||||
|
}
|
||||||
|
if (manageTimelinesToRemove.size() > 0) {
|
||||||
|
manageTimelines.removeAll(manageTimelinesToRemove);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
String instance = Helper.getLiveInstance(contextReference.get());
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
editor.putString(Helper.LAST_DATE_LIST_FETCH+userId+instance, Helper.dateToString(new Date()));
|
||||||
|
editor.apply();
|
||||||
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Iterator<ManageTimelines> it = manageTimelines.iterator(); it.hasNext(); ) {
|
for (Iterator<ManageTimelines> it = manageTimelines.iterator(); it.hasNext(); ) {
|
||||||
|
|
|
@ -3969,13 +3969,27 @@ public class API {
|
||||||
lists = parseLists(new JSONArray(response));
|
lists = parseLists(new JSONArray(response));
|
||||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
setError(e.getStatusCode(), e);
|
setError(e.getStatusCode(), e);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
}
|
||||||
e.printStackTrace();
|
apiResponse.setLists(lists);
|
||||||
} catch (KeyManagementException e) {
|
return apiResponse;
|
||||||
e.printStackTrace();
|
}
|
||||||
} catch (JSONException e) {
|
|
||||||
|
/**
|
||||||
|
* Get lists for the user
|
||||||
|
*
|
||||||
|
* @return APIResponse
|
||||||
|
*/
|
||||||
|
public APIResponse getListsRemote(String prefKeyOauthTokenT) {
|
||||||
|
apiResponse = new APIResponse();
|
||||||
|
List<app.fedilab.android.client.Entities.List> lists = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/lists"), 5, null, prefKeyOauthTokenT);
|
||||||
|
lists = parseLists(new JSONArray(response));
|
||||||
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
|
setError(e.getStatusCode(), e);
|
||||||
|
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
apiResponse.setLists(lists);
|
apiResponse.setLists(lists);
|
||||||
|
|
|
@ -200,6 +200,7 @@ import javax.net.ssl.SSLContext;
|
||||||
import app.fedilab.android.BuildConfig;
|
import app.fedilab.android.BuildConfig;
|
||||||
import app.fedilab.android.activities.MutedInstanceActivity;
|
import app.fedilab.android.activities.MutedInstanceActivity;
|
||||||
import app.fedilab.android.asynctasks.PostActionAsyncTask;
|
import app.fedilab.android.asynctasks.PostActionAsyncTask;
|
||||||
|
import app.fedilab.android.asynctasks.WhoToFollowAsyncTask;
|
||||||
import app.fedilab.android.client.API;
|
import app.fedilab.android.client.API;
|
||||||
import app.fedilab.android.client.APIResponse;
|
import app.fedilab.android.client.APIResponse;
|
||||||
import app.fedilab.android.client.Entities.Account;
|
import app.fedilab.android.client.Entities.Account;
|
||||||
|
@ -215,6 +216,7 @@ import app.fedilab.android.client.Entities.Status;
|
||||||
import app.fedilab.android.client.Entities.Tag;
|
import app.fedilab.android.client.Entities.Tag;
|
||||||
import app.fedilab.android.client.Entities.TagTimeline;
|
import app.fedilab.android.client.Entities.TagTimeline;
|
||||||
import app.fedilab.android.client.Tls12SocketFactory;
|
import app.fedilab.android.client.Tls12SocketFactory;
|
||||||
|
import app.fedilab.android.fragments.WhoToFollowFragment;
|
||||||
import app.fedilab.android.services.LiveNotificationDelayedService;
|
import app.fedilab.android.services.LiveNotificationDelayedService;
|
||||||
import app.fedilab.android.services.LiveNotificationService;
|
import app.fedilab.android.services.LiveNotificationService;
|
||||||
import app.fedilab.android.sqlite.MainMenuDAO;
|
import app.fedilab.android.sqlite.MainMenuDAO;
|
||||||
|
@ -319,7 +321,7 @@ public class Helper {
|
||||||
public static final String LAST_DATE_LIST_NAME_REFRESH = "last_date_list_name_refresh";
|
public static final String LAST_DATE_LIST_NAME_REFRESH = "last_date_list_name_refresh";
|
||||||
public static final String LAST_LIST = "last_list";
|
public static final String LAST_LIST = "last_list";
|
||||||
public static final String LAST_LIST_NAME = "last_list_name";
|
public static final String LAST_LIST_NAME = "last_list_name";
|
||||||
|
public static final String LAST_DATE_LIST_FETCH = "last_date_list_fetch";
|
||||||
|
|
||||||
//Notifications
|
//Notifications
|
||||||
public static final int NOTIFICATION_INTENT = 1;
|
public static final int NOTIFICATION_INTENT = 1;
|
||||||
|
@ -508,6 +510,7 @@ public class Helper {
|
||||||
public static final String INTENT_BACKUP_FINISH = "intent_backup_finish";
|
public static final String INTENT_BACKUP_FINISH = "intent_backup_finish";
|
||||||
public static final String INTENT_SEND_MODIFIED_IMAGE = "intent_send_modified_image";
|
public static final String INTENT_SEND_MODIFIED_IMAGE = "intent_send_modified_image";
|
||||||
public static final String INTENT_ADD_UPLOADED_MEDIA = "intent_add_uploaded_media";
|
public static final String INTENT_ADD_UPLOADED_MEDIA = "intent_add_uploaded_media";
|
||||||
|
public static final String REFRESH_LIST_TIMELINE = "refresh_list_timeline";
|
||||||
//Receiver
|
//Receiver
|
||||||
public static final String RECEIVE_DATA = "receive_data";
|
public static final String RECEIVE_DATA = "receive_data";
|
||||||
public static final String RECEIVE_ACTION = "receive_action";
|
public static final String RECEIVE_ACTION = "receive_action";
|
||||||
|
@ -4977,4 +4980,15 @@ public class Helper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean canFetchList(Context context, Account account){
|
||||||
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
String lastDateListRefresh = sharedpreferences.getString(Helper.LAST_DATE_LIST_FETCH+account.getId()+account.getInstance(), null);
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(new Date());
|
||||||
|
cal.add(Calendar.HOUR, -24);
|
||||||
|
Date dateAllowed = cal.getTime();
|
||||||
|
Date lastRefresh = Helper.stringToDate(context, lastDateListRefresh);
|
||||||
|
return (lastRefresh == null || lastRefresh.before(dateAllowed));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue