2019-10-01 18:11:43 +02:00
|
|
|
package app.fedilab.android.fragments;
|
|
|
|
/* 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>. */
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
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 app.fedilab.android.R;
|
|
|
|
import app.fedilab.android.activities.MainActivity;
|
|
|
|
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
|
|
|
|
import app.fedilab.android.client.APIResponse;
|
|
|
|
import app.fedilab.android.client.Entities.Status;
|
|
|
|
import app.fedilab.android.drawers.PixelfedListAdapter;
|
|
|
|
import app.fedilab.android.helper.Helper;
|
|
|
|
import app.fedilab.android.interfaces.OnRetrieveFeedsInterface;
|
|
|
|
import app.fedilab.android.sqlite.Sqlite;
|
|
|
|
import app.fedilab.android.sqlite.StatusCacheDAO;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 01/10/2019.
|
|
|
|
* Fragment to display bookmarks for Pixelfed
|
|
|
|
*/
|
|
|
|
public class DisplayBookmarksPixelfedFragment extends Fragment implements OnRetrieveFeedsInterface {
|
|
|
|
|
|
|
|
|
|
|
|
private Context context;
|
|
|
|
private List<Status> statuses;
|
|
|
|
private PixelfedListAdapter pixelfedListAdapter;
|
|
|
|
private RelativeLayout textviewNoAction;
|
|
|
|
private RelativeLayout mainLoader;
|
|
|
|
private RecyclerView lv_status;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
View rootView = inflater.inflate(R.layout.fragment_bookmarks, container, false);
|
|
|
|
context = getContext();
|
|
|
|
|
|
|
|
lv_status = rootView.findViewById(R.id.lv_status);
|
|
|
|
|
|
|
|
mainLoader = rootView.findViewById(R.id.loader);
|
|
|
|
textviewNoAction = rootView.findViewById(R.id.no_action);
|
|
|
|
mainLoader.setVisibility(View.VISIBLE);
|
|
|
|
new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, null, DisplayBookmarksPixelfedFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
|
|
|
|
return rootView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle saveInstance) {
|
|
|
|
super.onCreate(saveInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(@NotNull Context context) {
|
|
|
|
super.onAttach(context);
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRetrieveFeeds(APIResponse apiResponse) {
|
|
|
|
|
2020-04-09 18:57:12 +02:00
|
|
|
final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2019-10-01 18:11:43 +02:00
|
|
|
mainLoader.setVisibility(View.GONE);
|
|
|
|
FloatingActionButton delete_all = null;
|
|
|
|
try {
|
|
|
|
delete_all = ((MainActivity) context).findViewById(R.id.delete_all);
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
|
|
|
final boolean isOnWifi = Helper.isOnWIFI(context);
|
|
|
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
statuses = apiResponse.getStatuses();
|
|
|
|
if (statuses != null && statuses.size() > 0) {
|
|
|
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(context);
|
2019-11-15 16:32:25 +01:00
|
|
|
pixelfedListAdapter = new PixelfedListAdapter(RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, this.statuses);
|
2019-10-01 18:11:43 +02:00
|
|
|
lv_status.setAdapter(pixelfedListAdapter);
|
|
|
|
lv_status.setLayoutManager(mLayoutManager);
|
|
|
|
} else {
|
|
|
|
textviewNoAction.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delete_all != null)
|
|
|
|
delete_all.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
final SharedPreferences sharedpreferences = context.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(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) {
|
|
|
|
new StatusCacheDAO(context, db).removeAllStatus(StatusCacheDAO.BOOKMARK_CACHE);
|
|
|
|
statuses = new ArrayList<>();
|
|
|
|
statuses.clear();
|
|
|
|
pixelfedListAdapter = new PixelfedListAdapter(RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, statuses);
|
|
|
|
lv_status.setAdapter(pixelfedListAdapter);
|
|
|
|
pixelfedListAdapter.notifyDataSetChanged();
|
|
|
|
textviewNoAction.setVisibility(View.VISIBLE);
|
|
|
|
dialogConfirm.dismiss();
|
|
|
|
}
|
|
|
|
})
|
2019-11-11 09:34:13 +01:00
|
|
|
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
2019-10-01 18:11:43 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogConfirm, int which) {
|
|
|
|
dialogConfirm.dismiss();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|