forked from mirrors/Fedilab
Delete cache for all timelines after 7 days
This commit is contained in:
parent
fd9d9ba2e0
commit
d2f9c13f2e
3 changed files with 41 additions and 4 deletions
|
@ -124,6 +124,7 @@ import app.fedilab.android.client.entities.app.BottomMenu;
|
||||||
import app.fedilab.android.client.entities.app.DomainsBlock;
|
import app.fedilab.android.client.entities.app.DomainsBlock;
|
||||||
import app.fedilab.android.client.entities.app.Pinned;
|
import app.fedilab.android.client.entities.app.Pinned;
|
||||||
import app.fedilab.android.client.entities.app.PinnedTimeline;
|
import app.fedilab.android.client.entities.app.PinnedTimeline;
|
||||||
|
import app.fedilab.android.client.entities.app.StatusCache;
|
||||||
import app.fedilab.android.client.entities.app.StatusDraft;
|
import app.fedilab.android.client.entities.app.StatusDraft;
|
||||||
import app.fedilab.android.client.entities.app.Timeline;
|
import app.fedilab.android.client.entities.app.Timeline;
|
||||||
import app.fedilab.android.databinding.ActivityMainBinding;
|
import app.fedilab.android.databinding.ActivityMainBinding;
|
||||||
|
@ -760,6 +761,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
currentAccount = new Account(BaseMainActivity.this).getConnectedAccount();
|
currentAccount = new Account(BaseMainActivity.this).getConnectedAccount();
|
||||||
|
//Delete cache older than 7 days
|
||||||
|
new StatusCache(BaseMainActivity.this).deleteForAllAccountAfter7Days();
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import com.google.gson.Gson;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -385,6 +386,29 @@ public class StatusCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete all cache for all account after 7 days
|
||||||
|
*
|
||||||
|
* @return long - db id
|
||||||
|
* @throws DBException exception with database
|
||||||
|
*/
|
||||||
|
public long deleteForAllAccountAfter7Days() throws DBException {
|
||||||
|
if (db == null) {
|
||||||
|
throw new DBException("db is null. Wrong initialization.");
|
||||||
|
}
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(new Date());
|
||||||
|
cal.add(Calendar.DATE, -7);
|
||||||
|
Date date = cal.getTime();
|
||||||
|
String dateStr = Helper.dateToString(date);
|
||||||
|
try {
|
||||||
|
return db.delete(Sqlite.TABLE_STATUS_CACHE, Sqlite.COL_CREATED_AT + " < ?", new String[]{dateStr});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delete all cache for an account
|
* delete all cache for an account
|
||||||
*
|
*
|
||||||
|
|
|
@ -123,10 +123,6 @@ public class PinnedTimelineHelper {
|
||||||
params.setMargins(0, 0, 0, actionBarHeight);
|
params.setMargins(0, 0, 0, actionBarHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Remove badge when reselecting
|
|
||||||
activityMainBinding.bottomNavView.setOnItemReselectedListener(item -> {
|
|
||||||
activityMainBinding.bottomNavView.removeBadge(item.getItemId());
|
|
||||||
});
|
|
||||||
|
|
||||||
activityMainBinding.viewPager.setLayoutParams(params);
|
activityMainBinding.viewPager.setLayoutParams(params);
|
||||||
List<PinnedTimeline> pinnedTimelines = pinned.pinnedTimelines;
|
List<PinnedTimeline> pinnedTimelines = pinned.pinnedTimelines;
|
||||||
|
@ -501,6 +497,20 @@ public class PinnedTimelineHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTabReselected(TabLayout.Tab tab) {
|
public void onTabReselected(TabLayout.Tab tab) {
|
||||||
|
if (!singleBar && tab.getTag() != null) {
|
||||||
|
if (tab.getTag().equals(Timeline.TimeLineEnum.HOME.getValue())) {
|
||||||
|
activityMainBinding.bottomNavView.removeBadge(R.id.nav_home);
|
||||||
|
} else if (tab.getTag().equals(Timeline.TimeLineEnum.LOCAL.getValue())) {
|
||||||
|
activityMainBinding.bottomNavView.removeBadge(R.id.nav_local);
|
||||||
|
} else if (tab.getTag().equals(Timeline.TimeLineEnum.PUBLIC.getValue())) {
|
||||||
|
activityMainBinding.bottomNavView.removeBadge(R.id.nav_public);
|
||||||
|
} else if (tab.getTag().equals(Timeline.TimeLineEnum.NOTIFICATION.getValue())) {
|
||||||
|
activityMainBinding.bottomNavView.removeBadge(R.id.nav_notifications);
|
||||||
|
} else if (tab.getTag().equals(Timeline.TimeLineEnum.CONVERSATION.getValue())) {
|
||||||
|
activityMainBinding.bottomNavView.removeBadge(R.id.nav_privates);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Fragment fragment = fedilabPageAdapter.getCurrentFragment();
|
Fragment fragment = fedilabPageAdapter.getCurrentFragment();
|
||||||
View view = tab.getCustomView();
|
View view = tab.getCustomView();
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
|
|
Loading…
Reference in a new issue