Import/export
This commit is contained in:
parent
372d2dfe32
commit
b7f14397e0
|
@ -381,6 +381,11 @@
|
||||||
android:windowSoftInputMode="stateAlwaysHidden"
|
android:windowSoftInputMode="stateAlwaysHidden"
|
||||||
android:configChanges="orientation|screenSize"
|
android:configChanges="orientation|screenSize"
|
||||||
android:label="@string/app_name" />
|
android:label="@string/app_name" />
|
||||||
|
<activity
|
||||||
|
android:name="app.fedilab.android.activities.BookmarkActivity"
|
||||||
|
android:windowSoftInputMode="stateAlwaysHidden"
|
||||||
|
android:configChanges="orientation|screenSize"
|
||||||
|
android:label="@string/app_name" />
|
||||||
<activity
|
<activity
|
||||||
android:name="app.fedilab.android.activities.SettingsActivity"
|
android:name="app.fedilab.android.activities.SettingsActivity"
|
||||||
android:windowSoftInputMode="stateAlwaysHidden"
|
android:windowSoftInputMode="stateAlwaysHidden"
|
||||||
|
|
|
@ -1732,6 +1732,10 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
Intent intent = new Intent(getApplicationContext(), MutedInstanceActivity.class);
|
Intent intent = new Intent(getApplicationContext(), MutedInstanceActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return false;
|
return false;
|
||||||
|
}else if ( id == R.id.nav_bookmarks && ( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA)){
|
||||||
|
Intent intent = new Intent(getApplicationContext(), BookmarkActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
final NavigationView navigationView = findViewById(R.id.nav_view);
|
final NavigationView navigationView = findViewById(R.id.nav_view);
|
||||||
Helper.unCheckAllMenuItems(navigationView);
|
Helper.unCheckAllMenuItems(navigationView);
|
||||||
|
@ -1864,10 +1868,10 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
.replace(R.id.main_app_container, displayDraftsFragment, fragmentTag).commit();
|
.replace(R.id.main_app_container, displayDraftsFragment, fragmentTag).commit();
|
||||||
toot.hide();
|
toot.hide();
|
||||||
} else if (id == R.id.nav_bookmarks ) {
|
} else if (id == R.id.nav_bookmarks ) {
|
||||||
DisplayBookmarksFragment displayBookmarksFragment = new DisplayBookmarksFragment();
|
DisplayBookmarksFragment displayBookmarksFragment = new DisplayBookmarksFragment();
|
||||||
fragmentTag = "BOOKMARKS";
|
fragmentTag = "BOOKMARKS";
|
||||||
fragmentManager.beginTransaction()
|
fragmentManager.beginTransaction()
|
||||||
.replace(R.id.main_app_container, displayBookmarksFragment, fragmentTag).commit();
|
.replace(R.id.main_app_container, displayBookmarksFragment, fragmentTag).commit();
|
||||||
toot.hide();
|
toot.hide();
|
||||||
} else if (id == R.id.nav_pixelfed_bookmarks) {
|
} else if (id == R.id.nav_pixelfed_bookmarks) {
|
||||||
DisplayBookmarksPixelfedFragment displayBookmarksPixelfedFragment = new DisplayBookmarksPixelfedFragment();
|
DisplayBookmarksPixelfedFragment displayBookmarksPixelfedFragment = new DisplayBookmarksPixelfedFragment();
|
||||||
|
|
|
@ -0,0 +1,232 @@
|
||||||
|
/* Copyright 2019 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Fedilab
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
package app.fedilab.android.activities;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
|
||||||
|
import androidx.appcompat.app.ActionBar;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
|
import app.fedilab.android.R;
|
||||||
|
import app.fedilab.android.asynctasks.PostActionAsyncTask;
|
||||||
|
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
|
||||||
|
import app.fedilab.android.asynctasks.SyncBookmarksAsyncTask;
|
||||||
|
import app.fedilab.android.client.API;
|
||||||
|
import app.fedilab.android.client.APIResponse;
|
||||||
|
import app.fedilab.android.client.Entities.Account;
|
||||||
|
import app.fedilab.android.client.Entities.Status;
|
||||||
|
import app.fedilab.android.drawers.StatusListAdapter;
|
||||||
|
import app.fedilab.android.helper.Helper;
|
||||||
|
import app.fedilab.android.interfaces.OnRetrieveFeedsInterface;
|
||||||
|
import app.fedilab.android.interfaces.OnSyncBookmarksInterface;
|
||||||
|
import app.fedilab.android.sqlite.AccountDAO;
|
||||||
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 15/11/2019.
|
||||||
|
* Bookmark activity
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class BookmarkActivity extends BaseActivity implements OnRetrieveFeedsInterface, OnSyncBookmarksInterface {
|
||||||
|
|
||||||
|
private List<Status> statuses;
|
||||||
|
private StatusListAdapter statusListAdapter;
|
||||||
|
private RelativeLayout textviewNoAction;
|
||||||
|
private RelativeLayout mainLoader;
|
||||||
|
private RecyclerView lv_status;
|
||||||
|
private ImageView pp_actionBar;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||||
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||||
|
switch (theme) {
|
||||||
|
case Helper.THEME_LIGHT:
|
||||||
|
setTheme(R.style.AppTheme_Fedilab);
|
||||||
|
break;
|
||||||
|
case Helper.THEME_DARK:
|
||||||
|
setTheme(R.style.AppThemeDark);
|
||||||
|
break;
|
||||||
|
case Helper.THEME_BLACK:
|
||||||
|
setTheme(R.style.AppThemeBlack);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
setTheme(R.style.AppThemeDark);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getSupportActionBar() != null)
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
ActionBar actionBar = getSupportActionBar();
|
||||||
|
if (actionBar != null) {
|
||||||
|
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(BookmarkActivity.this, R.color.cyanea_primary)));
|
||||||
|
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||||
|
assert inflater != null;
|
||||||
|
View view = inflater.inflate(R.layout.simple_action_bar, new LinearLayout(getApplicationContext()), false);
|
||||||
|
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
|
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
|
TextView title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
|
||||||
|
pp_actionBar = actionBar.getCustomView().findViewById(R.id.pp_actionBar);
|
||||||
|
title.setText(R.string.bookmarks);
|
||||||
|
ImageView close_conversation = actionBar.getCustomView().findViewById(R.id.close_conversation);
|
||||||
|
if (close_conversation != null) {
|
||||||
|
close_conversation.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setTitle(R.string.bookmarks);
|
||||||
|
}
|
||||||
|
setContentView(R.layout.activity_bookmark);
|
||||||
|
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
||||||
|
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||||
|
|
||||||
|
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||||
|
|
||||||
|
lv_status = findViewById(R.id.lv_status);
|
||||||
|
|
||||||
|
mainLoader = findViewById(R.id.loader);
|
||||||
|
textviewNoAction = findViewById(R.id.no_action);
|
||||||
|
mainLoader.setVisibility(View.VISIBLE);
|
||||||
|
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, null, BookmarkActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case android.R.id.home:
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
case R.id.action_export_bookmarks:
|
||||||
|
new SyncBookmarksAsyncTask(BookmarkActivity.this, SyncBookmarksAsyncTask.sync.EXPORT, BookmarkActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
return true;
|
||||||
|
case R.id.action_import_bookmarks:
|
||||||
|
new SyncBookmarksAsyncTask(BookmarkActivity.this, SyncBookmarksAsyncTask.sync.IMPORT, BookmarkActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
|
||||||
|
getMenuInflater().inflate(R.menu.bookmarks, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||||
|
mainLoader.setVisibility(View.GONE);
|
||||||
|
FloatingActionButton delete_all = null;
|
||||||
|
try {
|
||||||
|
delete_all = findViewById(R.id.delete_all);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
final boolean isOnWifi = Helper.isOnWIFI(BookmarkActivity.this);
|
||||||
|
statuses = apiResponse.getStatuses();
|
||||||
|
if (statuses != null && statuses.size() > 0) {
|
||||||
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(BookmarkActivity.this);
|
||||||
|
statusListAdapter = new StatusListAdapter(RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, null, isOnWifi, this.statuses);
|
||||||
|
lv_status.setAdapter(statusListAdapter);
|
||||||
|
lv_status.setLayoutManager(mLayoutManager);
|
||||||
|
} else {
|
||||||
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delete_all != null)
|
||||||
|
delete_all.setOnClickListener(view -> {
|
||||||
|
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||||
|
int style;
|
||||||
|
if (theme == Helper.THEME_DARK) {
|
||||||
|
style = R.style.DialogDark;
|
||||||
|
} else if (theme == Helper.THEME_BLACK) {
|
||||||
|
style = R.style.DialogBlack;
|
||||||
|
} else {
|
||||||
|
style = R.style.Dialog;
|
||||||
|
}
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(BookmarkActivity.this, style);
|
||||||
|
builder.setTitle(R.string.delete_all);
|
||||||
|
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
|
.setPositiveButton(R.string.yes, (dialogConfirm, which) -> {
|
||||||
|
statuses = new ArrayList<>();
|
||||||
|
statuses.clear();
|
||||||
|
statusListAdapter = new StatusListAdapter(RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, null, isOnWifi, statuses);
|
||||||
|
lv_status.setAdapter(statusListAdapter);
|
||||||
|
statusListAdapter.notifyDataSetChanged();
|
||||||
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
|
new PostActionAsyncTask(BookmarkActivity.this, API.StatusAction.UNBOOKMARK).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
dialogConfirm.dismiss();
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.no, (dialogConfirm, which) -> dialogConfirm.dismiss())
|
||||||
|
.show();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRetrieveBookmarks(List<Status> bookmarks) {
|
||||||
|
if( bookmarks != null) {
|
||||||
|
statuses = new ArrayList<>();
|
||||||
|
statuses.clear();
|
||||||
|
statuses.addAll(bookmarks);
|
||||||
|
final boolean isOnWifi = Helper.isOnWIFI(BookmarkActivity.this);
|
||||||
|
statusListAdapter = new StatusListAdapter(RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, null, isOnWifi, statuses);
|
||||||
|
lv_status.setAdapter(statusListAdapter);
|
||||||
|
statusListAdapter.notifyDataSetChanged();
|
||||||
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,99 @@
|
||||||
|
/* Copyright 2019 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Fedilab
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
package app.fedilab.android.asynctasks;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import app.fedilab.android.client.API;
|
||||||
|
import app.fedilab.android.client.APIResponse;
|
||||||
|
import app.fedilab.android.interfaces.OnSyncBookmarksInterface;
|
||||||
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
|
import app.fedilab.android.sqlite.StatusCacheDAO;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 15/11/2019.
|
||||||
|
* Sync bookmarks
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SyncBookmarksAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
|
public enum sync{
|
||||||
|
EXPORT,
|
||||||
|
IMPORT
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<app.fedilab.android.client.Entities.Status> statusList;
|
||||||
|
private OnSyncBookmarksInterface listener;
|
||||||
|
private WeakReference<Context> contextReference;
|
||||||
|
private sync type;
|
||||||
|
|
||||||
|
public SyncBookmarksAsyncTask(Context context, sync type, OnSyncBookmarksInterface onSyncBookmarksInterface) {
|
||||||
|
this.contextReference = new WeakReference<>(context);
|
||||||
|
this.type = type;
|
||||||
|
this.listener = onSyncBookmarksInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... params) {
|
||||||
|
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
if( type == sync.EXPORT){
|
||||||
|
String max_id = null;
|
||||||
|
do {
|
||||||
|
APIResponse apiResponse = new API(contextReference.get()).getBookmarks(max_id);
|
||||||
|
max_id = apiResponse.getMax_id();
|
||||||
|
List<app.fedilab.android.client.Entities.Status> statuses = apiResponse.getStatuses();
|
||||||
|
for (app.fedilab.android.client.Entities.Status tmpStatus : statuses) {
|
||||||
|
app.fedilab.android.client.Entities.Status status = new StatusCacheDAO(contextReference.get(), db).getStatus(StatusCacheDAO.BOOKMARK_CACHE, tmpStatus.getId());
|
||||||
|
if( status == null) {
|
||||||
|
new StatusCacheDAO(contextReference.get(), db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, tmpStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(200);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
SystemClock.sleep(200);
|
||||||
|
}
|
||||||
|
} while (max_id != null);
|
||||||
|
}else{
|
||||||
|
List<app.fedilab.android.client.Entities.Status> statuses = new StatusCacheDAO(contextReference.get(), db).getAllStatus(StatusCacheDAO.BOOKMARK_CACHE);
|
||||||
|
if( statuses != null) {
|
||||||
|
for (app.fedilab.android.client.Entities.Status tmpStatus : statuses) {
|
||||||
|
new API(contextReference.get()).postAction(API.StatusAction.BOOKMARK, tmpStatus.getId());
|
||||||
|
try {
|
||||||
|
Thread.sleep(200);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
SystemClock.sleep(200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
statusList = new StatusCacheDAO(contextReference.get(), db).getAllStatus(StatusCacheDAO.BOOKMARK_CACHE);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void result) {
|
||||||
|
listener.onRetrieveBookmarks(statusList);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2603,6 +2603,36 @@ public class API {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves bookmarked status for the authenticated account *synchronously*
|
||||||
|
*
|
||||||
|
* @param max_id String id max
|
||||||
|
* @return APIResponse
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("SameParameterValue")
|
||||||
|
public APIResponse getBookmarks(String max_id) {
|
||||||
|
|
||||||
|
HashMap<String, String> params = new HashMap<>();
|
||||||
|
if (max_id != null)
|
||||||
|
params.put("max_id", max_id);
|
||||||
|
params.put("limit", "40");
|
||||||
|
statuses = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||||
|
String response = httpsConnection.get(getAbsoluteUrl("/bookmarks"), 10, params, prefKeyOauthTokenT);
|
||||||
|
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||||
|
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||||
|
statuses = parseStatuses(context, new JSONArray(response));
|
||||||
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
|
setError(e.getStatusCode(), e);
|
||||||
|
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
apiResponse.setStatuses(statuses);
|
||||||
|
return apiResponse;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes the post action for a status
|
* Makes the post action for a status
|
||||||
*
|
*
|
||||||
|
|
|
@ -15,9 +15,7 @@ package app.fedilab.android.fragments;
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
@ -46,8 +44,6 @@ import app.fedilab.android.client.APIResponse;
|
||||||
import app.fedilab.android.client.Entities.Status;
|
import app.fedilab.android.client.Entities.Status;
|
||||||
import app.fedilab.android.drawers.StatusListAdapter;
|
import app.fedilab.android.drawers.StatusListAdapter;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
import app.fedilab.android.sqlite.Sqlite;
|
|
||||||
import app.fedilab.android.sqlite.StatusCacheDAO;
|
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.activities.MainActivity;
|
import app.fedilab.android.activities.MainActivity;
|
||||||
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
|
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
|
||||||
|
@ -101,7 +97,6 @@ public class DisplayBookmarksFragment extends Fragment implements OnRetrieveFeed
|
||||||
@Override
|
@Override
|
||||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||||
|
|
||||||
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
||||||
mainLoader.setVisibility(View.GONE);
|
mainLoader.setVisibility(View.GONE);
|
||||||
FloatingActionButton delete_all = null;
|
FloatingActionButton delete_all = null;
|
||||||
try {
|
try {
|
||||||
|
@ -109,7 +104,6 @@ public class DisplayBookmarksFragment extends Fragment implements OnRetrieveFeed
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
final boolean isOnWifi = Helper.isOnWIFI(context);
|
final boolean isOnWifi = Helper.isOnWIFI(context);
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
statuses = apiResponse.getStatuses();
|
statuses = apiResponse.getStatuses();
|
||||||
if (statuses != null && statuses.size() > 0) {
|
if (statuses != null && statuses.size() > 0) {
|
||||||
LinearLayoutManager mLayoutManager = new LinearLayoutManager(context);
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(context);
|
||||||
|
@ -121,44 +115,33 @@ public class DisplayBookmarksFragment extends Fragment implements OnRetrieveFeed
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delete_all != null)
|
if (delete_all != null)
|
||||||
delete_all.setOnClickListener(new View.OnClickListener() {
|
delete_all.setOnClickListener(view -> {
|
||||||
@Override
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
public void onClick(View view) {
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
int style;
|
||||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
if (theme == Helper.THEME_DARK) {
|
||||||
int style;
|
style = R.style.DialogDark;
|
||||||
if (theme == Helper.THEME_DARK) {
|
} else if (theme == Helper.THEME_BLACK) {
|
||||||
style = R.style.DialogDark;
|
style = R.style.DialogBlack;
|
||||||
} else if (theme == Helper.THEME_BLACK) {
|
} else {
|
||||||
style = R.style.DialogBlack;
|
style = R.style.Dialog;
|
||||||
} else {
|
|
||||||
style = R.style.Dialog;
|
|
||||||
}
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, style);
|
|
||||||
builder.setTitle(R.string.delete_all);
|
|
||||||
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
|
||||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogConfirm, int which) {
|
|
||||||
|
|
||||||
statuses = new ArrayList<>();
|
|
||||||
statuses.clear();
|
|
||||||
statusListAdapter = new StatusListAdapter(RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, null, isOnWifi, statuses);
|
|
||||||
lv_status.setAdapter(statusListAdapter);
|
|
||||||
statusListAdapter.notifyDataSetChanged();
|
|
||||||
textviewNoAction.setVisibility(View.VISIBLE);
|
|
||||||
new PostActionAsyncTask(context, API.StatusAction.UNBOOKMARK).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
||||||
dialogConfirm.dismiss();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogConfirm, int which) {
|
|
||||||
dialogConfirm.dismiss();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.show();
|
|
||||||
}
|
}
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context, style);
|
||||||
|
builder.setTitle(R.string.delete_all);
|
||||||
|
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
|
.setPositiveButton(R.string.yes, (dialogConfirm, which) -> {
|
||||||
|
|
||||||
|
statuses = new ArrayList<>();
|
||||||
|
statuses.clear();
|
||||||
|
statusListAdapter = new StatusListAdapter(RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, null, isOnWifi, statuses);
|
||||||
|
lv_status.setAdapter(statusListAdapter);
|
||||||
|
statusListAdapter.notifyDataSetChanged();
|
||||||
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
|
new PostActionAsyncTask(context, API.StatusAction.UNBOOKMARK).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
dialogConfirm.dismiss();
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.no, (dialogConfirm, which) -> dialogConfirm.dismiss())
|
||||||
|
.show();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* Copyright 2019 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Fedilab
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
package app.fedilab.android.interfaces;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import app.fedilab.android.client.Entities.Status;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 15/11/2019.
|
||||||
|
* Interface when syncing bookmarks
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface OnSyncBookmarksInterface {
|
||||||
|
|
||||||
|
void onRetrieveBookmarks(List<Status> statuses);
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||||
|
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="#FF000000" android:pathData="M9,16h6v-6h4l-7,-7 -7,7h4zM5,18h14v2L5,20z"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,5 @@
|
||||||
|
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||||
|
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="#FF000000" android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,59 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?><!--
|
||||||
|
Copyright 2017 Thomas Schneider
|
||||||
|
|
||||||
|
This file is a part of Fedilab
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
|
see <http://www.gnu.org/licenses>.
|
||||||
|
-->
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:paddingLeft="@dimen/fab_margin"
|
||||||
|
android:paddingRight="@dimen/fab_margin"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<!-- Listview status -->
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/lv_status"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:scrollbars="none" />
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/no_action"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:padding="10dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textSize="25sp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textStyle="italic|bold"
|
||||||
|
android:typeface="serif"
|
||||||
|
android:text="@string/bookmarks_empty"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
</RelativeLayout>
|
||||||
|
<!-- Main Loader -->
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/loader"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:indeterminate="true" />
|
||||||
|
</RelativeLayout>
|
||||||
|
</RelativeLayout>
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_export_bookmarks"
|
||||||
|
android:title="@string/export_bookmarks"
|
||||||
|
android:icon="@drawable/ic_export_bookmarks"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_import_bookmarks"
|
||||||
|
android:title="@string/import_bookmarks"
|
||||||
|
android:icon="@drawable/ic_import_bookmarks"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
|
||||||
|
</menu>
|
|
@ -1287,4 +1287,6 @@
|
||||||
<string name="export_theme">Export the theme</string>
|
<string name="export_theme">Export the theme</string>
|
||||||
<string name="export_theme_title">Tap here to export the current theme</string>
|
<string name="export_theme_title">Tap here to export the current theme</string>
|
||||||
<string name="theme_file_error">An error occurred when selecting the theme file</string>
|
<string name="theme_file_error">An error occurred when selecting the theme file</string>
|
||||||
|
<string name="export_bookmarks">Export bookmarks to the instance</string>
|
||||||
|
<string name="import_bookmarks">Import bookmarks from the instance</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue