comment #411 - Prepare views
This commit is contained in:
parent
e2965fa92b
commit
0fa5cf88dc
|
@ -117,6 +117,7 @@ import app.fedilab.android.client.Entities.Status;
|
|||
import app.fedilab.android.client.Entities.TagTimeline;
|
||||
import app.fedilab.android.drawers.AccountSearchDevAdapter;
|
||||
import app.fedilab.android.fragments.DisplayAccountsFragment;
|
||||
import app.fedilab.android.fragments.DisplayAnnouncementsFragment;
|
||||
import app.fedilab.android.fragments.DisplayBookmarksPixelfedFragment;
|
||||
import app.fedilab.android.fragments.DisplayDraftsFragment;
|
||||
import app.fedilab.android.fragments.DisplayFavoritesPeertubeFragment;
|
||||
|
@ -1855,6 +1856,12 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
fragmentTag = "NEWS";
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
|
||||
} else if (id == R.id.nav_announcements) {
|
||||
toot.hide();
|
||||
fragmentTag = "ANNOUNCEMENTS";
|
||||
DisplayAnnouncementsFragment displayAnnouncementsFragment = new DisplayAnnouncementsFragment();
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.main_app_container, displayAnnouncementsFragment, fragmentTag).commit();
|
||||
} else if (id == R.id.nav_blocked || id == R.id.nav_pixelfed_blocked) {
|
||||
toot.hide();
|
||||
accountsFragment = new DisplayAccountsFragment();
|
||||
|
|
|
@ -196,6 +196,9 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
case NEWS:
|
||||
apiResponse = api.getNews(max_id);
|
||||
break;
|
||||
case ANNOUNCEMENTS:
|
||||
apiResponse = api.getAnnouncements();
|
||||
break;
|
||||
case SCHEDULED_TOOTS:
|
||||
apiResponse = api.scheduledAction("GET", null, max_id, null);
|
||||
break;
|
||||
|
@ -487,6 +490,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
NOTIFICATION,
|
||||
SEARCH,
|
||||
NEWS,
|
||||
ANNOUNCEMENTS,
|
||||
|
||||
PSUBSCRIPTIONS,
|
||||
POVERVIEW,
|
||||
|
|
|
@ -597,10 +597,18 @@ public class API {
|
|||
try {
|
||||
announcement.setId(resobj.getString("id"));
|
||||
announcement.setContent(resobj.getString("content"));
|
||||
announcement.setPublishedAt(Helper.mstStringToDate(context, resobj.getString("published_at")));
|
||||
announcement.setUpdatedAt(Helper.mstStringToDate(context, resobj.getString("updated_at")));
|
||||
announcement.setStartAt(Helper.mstStringToDate(context, resobj.getString("starts_at")));
|
||||
announcement.setEndAt(Helper.mstStringToDate(context, resobj.getString("ends_at")));
|
||||
if( resobj.getString("published_at").compareTo("null") != 0) {
|
||||
announcement.setPublishedAt(Helper.mstStringToDate(context, resobj.getString("published_at")));
|
||||
}
|
||||
if( resobj.getString("updated_at").compareTo("null") != 0) {
|
||||
announcement.setUpdatedAt(Helper.mstStringToDate(context, resobj.getString("updated_at")));
|
||||
}
|
||||
if( resobj.getString("starts_at").compareTo("null") != 0) {
|
||||
announcement.setStartAt(Helper.mstStringToDate(context, resobj.getString("starts_at")));
|
||||
}
|
||||
if( resobj.getString("ends_at").compareTo("null") != 0) {
|
||||
announcement.setEndAt(Helper.mstStringToDate(context, resobj.getString("ends_at")));
|
||||
}
|
||||
announcement.setRead(resobj.getBoolean("read"));
|
||||
|
||||
announcement.setReactions(parseReaction(resobj.getJSONArray("reactions")));
|
||||
|
@ -4026,7 +4034,7 @@ public class API {
|
|||
List<Announcement> announcements = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/announcements"), 10, null, null);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/announcements"), 10, null, prefKeyOauthTokenT);
|
||||
announcements = parseAnnouncement(context, new JSONArray(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package app.fedilab.android.fragments;
|
||||
/* Copyright 2017 Thomas Schneider
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Fedilab
|
||||
*
|
||||
|
@ -15,124 +15,63 @@ package app.fedilab.android.fragments;
|
|||
* 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.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.MainActivity;
|
||||
import app.fedilab.android.client.Entities.StoredStatus;
|
||||
import app.fedilab.android.drawers.DraftsListAdapter;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.sqlite.Sqlite;
|
||||
import app.fedilab.android.sqlite.StatusStoredDAO;
|
||||
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import app.fedilab.android.client.APIResponse;
|
||||
import app.fedilab.android.client.Entities.Announcement;
|
||||
import app.fedilab.android.interfaces.OnRetrieveFeedsInterface;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 19/09/2017.
|
||||
* Fragment to display drafts toots
|
||||
* Created by Thomas on 08/03/2020.
|
||||
* Fragment to display announcements
|
||||
*/
|
||||
public class DisplayAnnouncementsFragment extends Fragment {
|
||||
public class DisplayAnnouncementsFragment extends Fragment implements OnRetrieveFeedsInterface {
|
||||
|
||||
|
||||
private Context context;
|
||||
private List<StoredStatus> drafts;
|
||||
private DraftsListAdapter draftsListAdapter;
|
||||
private List<Announcement> announcements;
|
||||
private RelativeLayout textviewNoAction;
|
||||
private AsyncTask<Void, Void, Void> asyncTask;
|
||||
private RelativeLayout mainLoader;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
View rootView = inflater.inflate(R.layout.fragment_drafts, container, false);
|
||||
View rootView = inflater.inflate(R.layout.fragment_announcements, container, false);
|
||||
context = getContext();
|
||||
|
||||
final ListView lv_draft_toots = rootView.findViewById(R.id.lv_draft_toots);
|
||||
|
||||
RelativeLayout mainLoader = rootView.findViewById(R.id.loader);
|
||||
final RecyclerView lv_annoucements = rootView.findViewById(R.id.lv_annoucements);
|
||||
mainLoader = rootView.findViewById(R.id.loader);
|
||||
textviewNoAction = rootView.findViewById(R.id.no_action);
|
||||
mainLoader.setVisibility(View.VISIBLE);
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
if (theme == Helper.THEME_DARK) {
|
||||
Helper.changeDrawableColor(context, R.drawable.ic_cancel, R.color.dark_text);
|
||||
} else {
|
||||
Helper.changeDrawableColor(context, R.drawable.ic_cancel, R.color.black);
|
||||
}
|
||||
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
//Removes all scheduled toots that have sent
|
||||
new StatusStoredDAO(context, db).removeAllSent();
|
||||
drafts = new StatusStoredDAO(context, db).getAllDrafts();
|
||||
if (drafts != null && drafts.size() > 0) {
|
||||
draftsListAdapter = new DraftsListAdapter(drafts, true, textviewNoAction);
|
||||
lv_draft_toots.setAdapter(draftsListAdapter);
|
||||
draftsListAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
FloatingActionButton delete_all = null;
|
||||
try {
|
||||
delete_all = ((MainActivity) context).findViewById(R.id.delete_all);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
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 StatusStoredDAO(context, db).removeAllDrafts();
|
||||
drafts = new ArrayList<>();
|
||||
drafts.clear();
|
||||
draftsListAdapter = new DraftsListAdapter(drafts, true, textviewNoAction);
|
||||
lv_draft_toots.setAdapter(draftsListAdapter);
|
||||
draftsListAdapter.notifyDataSetChanged();
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
dialogConfirm.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogConfirm, int which) {
|
||||
dialogConfirm.dismiss();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
});
|
||||
LinearLayoutManager mLayoutManager = new LinearLayoutManager(context);
|
||||
lv_annoucements.setLayoutManager(mLayoutManager);
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.ANNOUNCEMENTS, null,DisplayAnnouncementsFragment.this).execute();
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
|
||||
asyncTask.cancel(true);
|
||||
}
|
||||
@Override
|
||||
public void onCreate(Bundle saveInstance) {
|
||||
super.onCreate(saveInstance);
|
||||
|
@ -140,10 +79,33 @@ public class DisplayAnnouncementsFragment extends Fragment {
|
|||
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
public void onAttach(@NotNull Context context) {
|
||||
super.onAttach(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
if (apiResponse == null) {
|
||||
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}else {
|
||||
if (apiResponse.getError() != null) {
|
||||
if (apiResponse.getError().getError().length() < 100) {
|
||||
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toasty.error(context, getString(R.string.long_api_error, "\ud83d\ude05"), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
announcements = apiResponse.getAnnouncements();
|
||||
if( announcements == null || announcements.size() == 0 ){
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Copyright 2017 Thomas Schneider
|
||||
Copyright 2020 Thomas Schneider
|
||||
|
||||
This file is a part of Fedilab
|
||||
|
||||
|
@ -19,9 +19,9 @@
|
|||
android:layout_height="match_parent"
|
||||
android:paddingLeft="@dimen/fab_margin"
|
||||
android:paddingRight="@dimen/fab_margin">
|
||||
<!-- Listview drafts toots -->
|
||||
<ListView
|
||||
android:id="@+id/lv_draft_toots"
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/lv_annoucements"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:divider="@null"
|
||||
|
@ -33,7 +33,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/no_action_text"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -42,19 +41,18 @@
|
|||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:padding="10dp"
|
||||
android:text="@string/no_draft"
|
||||
android:text="@string/no_announcements"
|
||||
android:textSize="25sp"
|
||||
android:textStyle="italic|bold"
|
||||
android:typeface="serif" />
|
||||
</RelativeLayout>
|
||||
<!-- Main Loader -->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout
|
||||
android:id="@+id/loader"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:visibility="gone">
|
||||
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:divider="@null"
|
||||
android:paddingBottom="?attr/actionBarSize"
|
||||
android:scrollbars="none"></ListView>
|
||||
android:scrollbars="none"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/no_action"
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
android:id="@+id/menu_none"
|
||||
android:title=""
|
||||
android:visible="false" />
|
||||
<item
|
||||
android:id="@+id/nav_announcements"
|
||||
android:icon="@drawable/ic_bullhorn"
|
||||
android:title="@string/action_announcements"
|
||||
app:actionLayout="@layout/item_menu_news" />
|
||||
<item
|
||||
android:id="@+id/nav_news"
|
||||
android:icon="@drawable/ic_new_releases_black"
|
||||
|
|
|
@ -1222,4 +1222,6 @@
|
|||
<string name="action_disabled">Action disabled</string>
|
||||
<string name="action_unfollow">Unfollow</string>
|
||||
<string name="error_destination_path">Something went wrong, please check your download directory in settings.</string>
|
||||
<string name="action_announcements">Announcements</string>
|
||||
<string name="no_announcements">No announcements!</string>
|
||||
</resources>
|
Loading…
Reference in New Issue