Add all timeline in tabs

This commit is contained in:
tom79 2019-04-22 13:16:35 +02:00
parent 2df9d3193d
commit a528d878e5
9 changed files with 157 additions and 60 deletions

View File

@ -55,7 +55,6 @@ import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.util.Log;
import android.util.Patterns;
import android.util.SparseArray;
import android.view.Gravity;
@ -823,11 +822,12 @@ public abstract class BaseMainActivity extends BaseActivity
//Defines the current locale of the device in a static variable
currentLocale = Helper.currentLocale(getApplicationContext());
if( tabLayout.getTabAt(0) == null) {
/*if( tabLayout.getTabAt(0) == null) {
Helper.logout(BaseMainActivity.this);
return;
}
tabLayout.getTabAt(0).select();
*/
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
toot.setOnClickListener(new View.OnClickListener() {
@Override
@ -1829,7 +1829,8 @@ public abstract class BaseMainActivity extends BaseActivity
viewPager.setVisibility(View.VISIBLE);
delete_instance.setVisibility(View.GONE);
Helper.switchLayout(BaseMainActivity.this);
if( tab.getPosition() == 1 || (tabPosition.containsKey("art") && tab.getPosition() == tabPosition.get("art"))||(tabPosition.containsKey("peertube") && tab.getPosition() == tabPosition.get("peertube"))) {
//TODO: not hiding the compose button
if( manageTimelines.size() > tab.getPosition() && (manageTimelines.get(tab.getPosition()).getType() == ManageTimelines.Type.ART || manageTimelines.get(tab.getPosition()).getType() == ManageTimelines.Type.PEERTUBE)) {
toot.hide();
federatedTimelines.hide();
}else {
@ -1874,7 +1875,7 @@ public abstract class BaseMainActivity extends BaseActivity
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
}
if( tab.getPosition() == 1 || (tabPosition.containsKey("art") && tab.getPosition() == tabPosition.get("art"))||(tabPosition.containsKey("peertube") && tab.getPosition() == tabPosition.get("peertube"))) {
if( manageTimelines.size() > tab.getPosition() && (manageTimelines.get(tab.getPosition()).getType() == ManageTimelines.Type.ART || manageTimelines.get(tab.getPosition()).getType() == ManageTimelines.Type.PEERTUBE)) {
toot.hide();
federatedTimelines.hide();
}else {
@ -1995,19 +1996,19 @@ public abstract class BaseMainActivity extends BaseActivity
tabLayout.setVisibility(View.VISIBLE);
toolbar_search.setIconified(true);
}
//Selection comes from another menu, no action to do
Bundle bundle = new Bundle();
ManageTimelines tl = null;
for (ManageTimelines timeline: timelines){
if( timeline.getPosition() == position)
tl = timeline;
}
if( position < timelines.size())
tl = timelines.get(position);
if( tl == null)
return null;
if( tl.getType() != ManageTimelines.Type.NOTIFICATION){
DisplayStatusFragment displayStatusFragment = new DisplayStatusFragment();
RetrieveFeedsAsyncTask.Type type = ManageTimelines.transform(BaseMainActivity.this, tl.getType());
bundle.putSerializable("type", type);
if (tl.getType() == ManageTimelines.Type.TAG) {
TagTimeline ttl = tl.getTagTimeline();
bundle.putString("tag", ttl.getName());
@ -2022,7 +2023,10 @@ public abstract class BaseMainActivity extends BaseActivity
}else if( tl.getType() == ManageTimelines.Type.INSTANCE){
bundle.putString("remote_instance", tl.getRemoteInstance().getHost()!=null?tl.getRemoteInstance().getHost():"");
bundle.putString("instanceType", tl.getRemoteInstance().getType());
}else if( tl.getType() == ManageTimelines.Type.LIST){
bundle.putString("targetedid", tl.getListTimeline().getId());
}
displayStatusFragment.setArguments(bundle);
return displayStatusFragment;
}else{
return new TabLayoutNotificationsFragment();

View File

@ -30,6 +30,7 @@ import fr.gouv.etalab.mastodon.client.Entities.TagTimeline;
import fr.gouv.etalab.mastodon.client.GNUAPI;
import fr.gouv.etalab.mastodon.client.PeertubeAPI;
import fr.gouv.etalab.mastodon.helper.FilterToots;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
import fr.gouv.etalab.mastodon.sqlite.InstancesDAO;
import fr.gouv.etalab.mastodon.sqlite.PeertubeFavoritesDAO;
@ -119,6 +120,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
this.filterToots = filterToots;
}
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
this.contextReference = new WeakReference<>(context);
this.action = action;
@ -175,6 +177,8 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
API api = new API(this.contextReference.get());
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
if( action == null )
return null;
switch (action){
case HOME:
apiResponse = api.getHomeTimeline(max_id);

View File

@ -29,6 +29,7 @@ import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.ManageTimelines;
import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance;
import fr.gouv.etalab.mastodon.client.Entities.TagTimeline;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnSyncTimelineInterface;
import fr.gouv.etalab.mastodon.sqlite.InstancesDAO;
import fr.gouv.etalab.mastodon.sqlite.SearchDAO;
@ -61,55 +62,71 @@ public class SyncTimelinesAsyncTask extends AsyncTask<Void, Void, Void> {
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), DB_NAME, null, Sqlite.DB_VERSION).open();
manageTimelines = new TimelinesDAO(contextReference.get(), db).getAllTimelines();
//First time that the timeline is created
int i = 0;
if( manageTimelines == null || manageTimelines.size() == 0){
manageTimelines = new ArrayList<>();
//Add home TL
ManageTimelines manageHome = new ManageTimelines();
manageHome.setDisplayed(true);
manageHome.setType(ManageTimelines.Type.HOME);
manageHome.setPosition(0);
manageHome.setPosition(i);
manageTimelines.add(manageHome);
i++;
new TimelinesDAO(contextReference.get(), db).insert(manageHome);
//Add Direct notification TL
ManageTimelines manageNotif = new ManageTimelines();
manageNotif.setDisplayed(true);
manageNotif.setType(ManageTimelines.Type.NOTIFICATION);
manageNotif.setPosition(1);
manageNotif.setPosition(i);
i++;
manageTimelines.add(manageNotif);
new TimelinesDAO(contextReference.get(), db).insert(manageNotif);
//Add Direct message TL
ManageTimelines manageDirect = new ManageTimelines();
manageDirect.setDisplayed(true);
manageDirect.setType(ManageTimelines.Type.DIRECT);
manageDirect.setPosition(2);
manageDirect.setPosition(i);
i++;
manageTimelines.add(manageDirect);
new TimelinesDAO(contextReference.get(), db).insert(manageDirect);
//Add Local TL
ManageTimelines manageLocal = new ManageTimelines();
manageLocal.setDisplayed(true);
manageLocal.setType(ManageTimelines.Type.LOCAL);
manageLocal.setPosition(3);
manageLocal.setPosition(i);
i++;
manageTimelines.add(manageLocal);
//Add Public TL
ManageTimelines managePublic = new ManageTimelines();
managePublic.setDisplayed(true);
managePublic.setType(ManageTimelines.Type.PUBLIC);
managePublic.setPosition(4);
manageTimelines.add(managePublic);
//Add Public ART
ManageTimelines manageArt = new ManageTimelines();
manageArt.setDisplayed(true);
manageArt.setType(ManageTimelines.Type.ART);
manageArt.setPosition(5);
manageTimelines.add(manageArt);
//Add Public PEERTUBE
ManageTimelines managePeertube = new ManageTimelines();
managePeertube.setDisplayed(true);
managePeertube.setType(ManageTimelines.Type.ART);
managePeertube.setPosition(6);
manageTimelines.add(managePeertube);
new TimelinesDAO(contextReference.get(), db).insert(manageLocal);
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
//Add Public TL
ManageTimelines managePublic = new ManageTimelines();
managePublic.setDisplayed(true);
managePublic.setType(ManageTimelines.Type.PUBLIC);
managePublic.setPosition(i);
i++;
manageTimelines.add(managePublic);
new TimelinesDAO(contextReference.get(), db).insert(managePublic);
}
if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
//Add Public ART
ManageTimelines manageArt = new ManageTimelines();
manageArt.setDisplayed(true);
manageArt.setType(ManageTimelines.Type.ART);
manageArt.setPosition(i);
i++;
manageTimelines.add(manageArt);
new TimelinesDAO(contextReference.get(), db).insert(manageArt);
//Add Public PEERTUBE
ManageTimelines managePeertube = new ManageTimelines();
managePeertube.setDisplayed(true);
managePeertube.setType(ManageTimelines.Type.PEERTUBE);
managePeertube.setPosition(i);
i++;
manageTimelines.add(managePeertube);
new TimelinesDAO(contextReference.get(), db).insert(managePeertube);
}
int i = 6;
List<TagTimeline> tagTimelines = new SearchDAO(contextReference.get(), db).getAll();
if( tagTimelines != null && tagTimelines.size() > 0 ){
for(TagTimeline ttl: tagTimelines){
@ -117,9 +134,11 @@ public class SyncTimelinesAsyncTask extends AsyncTask<Void, Void, Void> {
ManageTimelines manageTagTimeline = new ManageTimelines();
manageTagTimeline.setDisplayed(true);
manageTagTimeline.setType(ManageTimelines.Type.TAG);
manageTagTimeline.setPosition(i++);
manageTagTimeline.setPosition(i);
manageTagTimeline.setTagTimeline(ttl);
manageTimelines.add(manageTagTimeline);
new TimelinesDAO(contextReference.get(), db).insert(manageTagTimeline);
i++;
}
}
List<RemoteInstance> instances = new InstancesDAO(contextReference.get(), db).getAllInstances();
@ -129,11 +148,14 @@ public class SyncTimelinesAsyncTask extends AsyncTask<Void, Void, Void> {
ManageTimelines manageRemoteTimline = new ManageTimelines();
manageRemoteTimline.setDisplayed(true);
manageRemoteTimline.setType(ManageTimelines.Type.INSTANCE);
manageRemoteTimline.setPosition(i++);
manageRemoteTimline.setPosition(i);
manageRemoteTimline.setRemoteInstance(ritl);
manageTimelines.add(manageRemoteTimline);
new TimelinesDAO(contextReference.get(), db).insert(manageRemoteTimline);
i++;
}
}
}else{
}
APIResponse apiResponse = new API(contextReference.get()).getLists();

View File

@ -66,7 +66,7 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
Account account = null;
Account account;
if( social == SOCIAL.MASTODON || social == SOCIAL.PIXELFED) {
account = new API(this.contextReference.get(), instance, null).verifyCredentials();
account.setSocial(account.getSocial());
@ -77,18 +77,17 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
account = new GNUAPI(this.contextReference.get(), instance, null).verifyCredentials();
account.setSocial(account.getSocial());
}
try {
//At the state the instance can be encoded
instance = URLDecoder.decode(instance, "utf-8");
} catch (UnsupportedEncodingException ignored) {}
SharedPreferences sharedpreferences = this.contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
account.setToken(token);
account.setClient_id(client_id);
account.setClient_secret(client_secret);
account.setRefresh_token(refresh_token);
account.setInstance(instance);
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
boolean userExists = new AccountDAO(this.contextReference.get(), db).userExist(account);
SharedPreferences.Editor editor = sharedpreferences.edit();

View File

@ -28,7 +28,6 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.widget.PopupMenu;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@ -36,9 +35,8 @@ import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.regex.Pattern;
import es.dmoral.toasty.Toasty;
@ -49,10 +47,8 @@ import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
import fr.gouv.etalab.mastodon.fragments.TabLayoutNotificationsFragment;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.sqlite.InstancesDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.sqlite.TimelinesDAO;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
import static fr.gouv.etalab.mastodon.sqlite.Sqlite.DB_NAME;
@ -283,19 +279,19 @@ public class ManageTimelines {
public void createTabs(Context context, TabLayout tabLayout, java.util.List<ManageTimelines> manageTimelines){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
for(ManageTimelines tl: manageTimelines){
TabLayout.Tab tb = tabLayout.newTab();
tb.setCustomView(R.layout.tab_badge);
ImageView icon = null;
if( tl.getType() != Type.TAG && tl.getType() != Type.INSTANCE && tl.getType() != Type.LIST) {
tb.setCustomView(R.layout.tab_badge);
if( tb.getCustomView() != null)
icon = tb.getCustomView().findViewById(R.id.tab_icon);
}
if( icon != null){
if( tl.getPosition() == 0)
icon.setColorFilter(ContextCompat.getColor(context, R.color.mastodonC4), PorterDuff.Mode.SRC_IN);
switch (tl.getType()){
case HOME:
icon.setImageResource(R.drawable.ic_home);
@ -332,6 +328,24 @@ public class ManageTimelines {
icon.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
}
tabLayout.addTab(tb);
}else{
if( tl.getType() == Type.TAG){
if( tl.getTagTimeline().getDisplayname() != null) {
tb.setText(tl.getTagTimeline().getDisplayname());
}else {
tb.setText(tl.getTagTimeline().getName());
}
}else if( tl.getType() == Type.INSTANCE){
tb.setText(tl.getRemoteInstance().getHost());
}else if( tl.getType() == Type.LIST){
tb.setText(tl.getListTimeline().getTitle());
}
tabLayout.addTab(tb);
if( tl.getPosition() == 0){
TextView tv = tabLayout.getChildAt(0).findViewById(android.R.id.title);
if( tv != null)
tv.setTextColor(ContextCompat.getColor(context, R.color.mastodonC4));
}
}
final LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0);
if( tl.getType() == Type.NOTIFICATION){
@ -348,7 +362,7 @@ public class ManageTimelines {
}
}
}
// tabLayout.getTabAt(0).select();
}
public static void insertUpdateTL(Context context, ManageTimelines manageTimelines){

View File

@ -32,7 +32,6 @@ import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -48,7 +47,9 @@ import java.util.List;
import es.dmoral.toasty.Toasty;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.BaseMainActivity;
import fr.gouv.etalab.mastodon.activities.ListActivity;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAfterBookmarkAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveMissingFeedsAsyncTask;
@ -68,6 +69,7 @@ import fr.gouv.etalab.mastodon.drawers.PeertubeAdapter;
import fr.gouv.etalab.mastodon.drawers.PixelfedListAdapter;
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsAfterBookmarkInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingFeedsInterface;
@ -85,7 +87,7 @@ import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO;
* Created by Thomas on 24/04/2017.
* Fragment to display content related to status
*/
public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsInterface, OnRetrieveMissingFeedsInterface, OnRetrieveFeedsAfterBookmarkInterface {
public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsInterface, OnRetrieveMissingFeedsInterface, OnRetrieveFeedsAfterBookmarkInterface, OnListActionInterface {
private boolean flag_loading;
@ -157,6 +159,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
remote_channel_name = bundle.getString("remote_channel_name", null);
instanceType = bundle.getString("instanceType", "MASTODON");
ischannel = bundle.getBoolean("ischannel",false);
}
if( ischannel)
type = RetrieveFeedsAsyncTask.Type.CHANNEL;
@ -991,24 +994,24 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
}
private void manageAsyncTask(boolean pagination){
private void manageAsyncTask(boolean pagination) {
//Message for an account
if (type == RetrieveFeedsAsyncTask.Type.USER || type == RetrieveFeedsAsyncTask.Type.CHANNEL)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, showReply,DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
//Tag timelines
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, showReply, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
//Tag timelines
else if (type == RetrieveFeedsAsyncTask.Type.TAG || type == RetrieveFeedsAsyncTask.Type.SEARCH)
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) {
else if (type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) {
//Remote instances
if( search_peertube == null) { //Not a Peertube search
if( remote_channel_name == null) { //Not a channel
if (search_peertube == null) { //Not a Peertube search
if (remote_channel_name == null) { //Not a channel
asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
else
} else
asyncTask = new RetrieveFeedsAsyncTask(context, remoteInstance, remote_channel_name, null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
else
} else
asyncTask = new RetrievePeertubeSearchAsyncTask(context, remoteInstance, search_peertube, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else if( type == RetrieveFeedsAsyncTask.Type.LIST){
new ManageListsAsyncTask(context,targetedId, max_id ,null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else {
if( !pagination) {
if (type == RetrieveFeedsAsyncTask.Type.HOME) {
@ -1029,4 +1032,46 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
@Override
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
//Discards 404 - error which can often happen due to toots which have been deleted
if (apiResponse.getError() != null) {
if ( !apiResponse.getError().getError().startsWith("404 -"))
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false);
isSwipped = false;
flag_loading = false;
return;
}
if( actionType == ManageListsAsyncTask.action.GET_LIST_TIMELINE) {
int previousPosition = this.statuses.size();
List<Status> statuses = apiResponse.getStatuses();
max_id = apiResponse.getMax_id();
flag_loading = (max_id == null);
if (!isSwipped && firstLoad && (statuses == null || statuses.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
else
textviewNoAction.setVisibility(View.GONE);
if (isSwipped) {
if (previousPosition > 0) {
for (int i = 0; i < previousPosition; i++) {
this.statuses.remove(0);
}
statusListAdapter.notifyItemRangeRemoved(0, previousPosition);
}
isSwipped = false;
}
if (statuses != null && statuses.size() > 0) {
this.statuses.addAll(statuses);
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
}
swipeRefreshLayout.setRefreshing(false);
firstLoad = false;
}
}
}

View File

@ -598,6 +598,7 @@ public class Helper {
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, newAccount.getToken());
editor.putString(Helper.PREF_KEY_ID, newAccount.getId());
editor.putString(Helper.PREF_INSTANCE, newAccount.getInstance().trim());
editor.putBoolean(Helper.PREF_IS_MODERATOR, newAccount.isModerator());
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, newAccount.isAdmin());
editor.commit();

View File

@ -265,7 +265,7 @@ public class Sqlite extends SQLiteOpenHelper {
static final String COL_REMOTE_INSTANCE = "REMOTE_INSTANCE";
static final String COL_TAG_TIMELINE = "TAG_TIMELINE";
private static final String CREATE_TABLE_TIMELINES = "CREATE TABLE " + TABLE_TIMELINES + " ("
private static final String CREATE_TABLE_TIMELINES = "CREATE TABLE IF NOT EXISTS " + TABLE_TIMELINES + " ("
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ COL_POSITION + " INTEGER NOT NULL, "
+ COL_USER_ID + " TEXT NOT NULL, " + COL_INSTANCE + " TEXT NOT NULL, "

View File

@ -65,6 +65,14 @@ public class TimelinesDAO {
return db.delete(Sqlite.TABLE_TIMELINES, Sqlite.COL_ID + " = \"" + timeline.getId() + "\"", null);
}
//------- REMOVE -------
public int removeAll(){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(context);
return db.delete(Sqlite.TABLE_TIMELINES, Sqlite.COL_USER_ID + " = '" + userId+ "' AND " + Sqlite.COL_INSTANCE + " = '" + instance+ "'", null);
}
//------- UPDATE -------
public int update(ManageTimelines timeline) {
ContentValues values = new ContentValues();