move some code

This commit is contained in:
Thomas 2020-07-14 09:44:16 +02:00
parent 2d69cf6dfa
commit ea4f2bd8e8
6 changed files with 66 additions and 31 deletions

View File

@ -60,6 +60,7 @@ android {
manifest.srcFile "src/main/AndroidManifest.xml" manifest.srcFile "src/main/AndroidManifest.xml"
java.srcDirs = ['src/main/java', 'src/playstore/java','src/common/java'] java.srcDirs = ['src/main/java', 'src/playstore/java','src/common/java']
} }
fdroid { fdroid {
manifest.srcFile "src/main/AndroidManifest.xml" manifest.srcFile "src/main/AndroidManifest.xml"
java.srcDirs = ['src/main/java', 'src/fdroid/java','src/common/java'] java.srcDirs = ['src/main/java', 'src/fdroid/java','src/common/java']

View File

@ -5,6 +5,7 @@ import android.os.Bundle;
import java.util.List; import java.util.List;
import app.fedilab.android.activities.OwnerNotificationChartsActivity;
import app.fedilab.android.client.Entities.Notification; import app.fedilab.android.client.Entities.Notification;
/* Copyright 2020 Thomas Schneider /* Copyright 2020 Thomas Schneider
@ -28,8 +29,8 @@ public class NotificationsListAdapter extends BaseNotificationsListAdapter{
} }
public void notificationStatusChart(){ public void notificationStatusChart(){
intent = new Intent(context, OwnerNotificationChartsActivity.class); Intent intent = new Intent(context, OwnerNotificationChartsActivity.class);
b = new Bundle(); Bundle b = new Bundle();
b.putString("status_id", status.getReblog() != null ? status.getReblog().getId() : status.getId()); b.putString("status_id", status.getReblog() != null ? status.getReblog().getId() : status.getId());
intent.putExtras(b); intent.putExtras(b);
context.startActivity(intent); context.startActivity(intent);

View File

@ -13,9 +13,14 @@ package app.fedilab.android.helper;
* *
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.content.SharedPreferences;
import org.conscrypt.Conscrypt; import org.conscrypt.Conscrypt;
import java.security.Security; import java.security.Security;
import app.fedilab.android.activities.MainApplication;
public class Helper extends BaseHelper { public class Helper extends BaseHelper {
public static void installProvider() { public static void installProvider() {

View File

@ -1,4 +1,32 @@
package app.fedilab.android.drawers; package app.fedilab.android.drawers;
public class NotificationsListAdapter { import android.content.Intent;
import android.os.Bundle;
import java.util.List;
import app.fedilab.android.client.Entities.Notification;
/* Copyright 2020 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>. */
public class NotificationsListAdapter extends BaseNotificationsListAdapter{
public NotificationsListAdapter(boolean isOnWifi, int behaviorWithAttachments, List<Notification> notifications) {
super(isOnWifi, behaviorWithAttachments, notifications);
}
public void notificationStatusChart(){}
} }

View File

@ -82,7 +82,6 @@ import app.fedilab.android.activities.AccountReportActivity;
import app.fedilab.android.activities.BaseActivity; import app.fedilab.android.activities.BaseActivity;
import app.fedilab.android.activities.CustomSharingActivity; import app.fedilab.android.activities.CustomSharingActivity;
import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.activities.OwnerNotificationChartsActivity;
import app.fedilab.android.activities.ShowAccountActivity; import app.fedilab.android.activities.ShowAccountActivity;
import app.fedilab.android.activities.ShowConversationActivity; import app.fedilab.android.activities.ShowConversationActivity;
import app.fedilab.android.activities.SlideMediaActivity; import app.fedilab.android.activities.SlideMediaActivity;
@ -125,18 +124,18 @@ import static app.fedilab.android.helper.Helper.makeEmojis;
* Adapter for Status * Adapter for Status
*/ */
public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements OnPostActionInterface, OnPostNotificationsActionInterface, OnRetrieveEmojiInterface, OnRetrieveEmojiAccountInterface, OnPollInterface, OnRetrieveImageInterface { public abstract class BaseNotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements OnPostActionInterface, OnPostNotificationsActionInterface, OnRetrieveEmojiInterface, OnRetrieveEmojiAccountInterface, OnPollInterface, OnRetrieveImageInterface {
private final Object lock = new Object(); private final Object lock = new Object();
private Context context; protected Context context;
private List<Notification> notifications; private List<Notification> notifications;
private NotificationsListAdapter notificationsListAdapter; private BaseNotificationsListAdapter notificationsListAdapter;
private int behaviorWithAttachments; private int behaviorWithAttachments;
private boolean isOnWifi; private boolean isOnWifi;
private NotificationsListAdapter.ViewHolder holder; private NotificationsListAdapter.ViewHolder holder;
private int style; private int style;
private RecyclerView mRecyclerView; private RecyclerView mRecyclerView;
protected Status status;
private Runnable updateAnimatedEmoji = new Runnable() { private Runnable updateAnimatedEmoji = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -156,7 +155,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
public NotificationsListAdapter(boolean isOnWifi, int behaviorWithAttachments, List<Notification> notifications) { public BaseNotificationsListAdapter(boolean isOnWifi, int behaviorWithAttachments, List<Notification> notifications) {
this.notifications = notifications; this.notifications = notifications;
notificationsListAdapter = this; notificationsListAdapter = this;
this.isOnWifi = isOnWifi; this.isOnWifi = isOnWifi;
@ -372,7 +371,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
holder.spark_button_reblog.setImageSize((int) (20 * iconSizePercent / 100 * scale + 0.5f)); holder.spark_button_reblog.setImageSize((int) (20 * iconSizePercent / 100 * scale + 0.5f));
holder.spark_button_reblog.setMinimumWidth((int) Helper.convertDpToPixel(((float) (20 * iconSizePercent) / 100 * scale + 0.5f), context)); holder.spark_button_reblog.setMinimumWidth((int) Helper.convertDpToPixel(((float) (20 * iconSizePercent) / 100 * scale + 0.5f), context));
final Status status = notification.getStatus(); status = notification.getStatus();
if (status != null) { if (status != null) {
if (status.getMedia_attachments() == null || status.getMedia_attachments().size() < 1) if (status.getMedia_attachments() == null || status.getMedia_attachments().size() < 1)
holder.status_document_container.setVisibility(View.GONE); holder.status_document_container.setVisibility(View.GONE);
@ -624,11 +623,11 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
if (choice[0] == -1) if (choice[0] == -1)
return; return;
} }
new ManagePollAsyncTask(context, ManagePollAsyncTask.type_s.SUBMIT, status, choice, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new ManagePollAsyncTask(context, ManagePollAsyncTask.type_s.SUBMIT, status, choice, BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}); });
} }
holder.refresh_poll.setOnClickListener(v -> new ManagePollAsyncTask(context, ManagePollAsyncTask.type_s.REFRESH, status, null, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)); holder.refresh_poll.setOnClickListener(v -> new ManagePollAsyncTask(context, ManagePollAsyncTask.type_s.REFRESH, status, null, BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR));
holder.poll_container.setVisibility(View.VISIBLE); holder.poll_container.setVisibility(View.VISIBLE);
holder.number_votes.setText(context.getResources().getQuantityString(R.plurals.number_of_voters, status.getPoll().getVoters_count(), status.getPoll().getVoters_count())); holder.number_votes.setText(context.getResources().getQuantityString(R.plurals.number_of_voters, status.getPoll().getVoters_count(), status.getPoll().getVoters_count()));
if (poll.isExpired()) { if (poll.isExpired()) {
@ -649,7 +648,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
status.setFavAnimated(true); status.setFavAnimated(true);
notifyNotificationChanged(notification); notifyNotificationChanged(notification);
} }
CrossActions.doCrossAction(context, null, status, null, status.isFavourited() ? API.StatusAction.UNFAVOURITE : API.StatusAction.FAVOURITE, notificationsListAdapter, NotificationsListAdapter.this, true); CrossActions.doCrossAction(context, null, status, null, status.isFavourited() ? API.StatusAction.UNFAVOURITE : API.StatusAction.FAVOURITE, notificationsListAdapter, BaseNotificationsListAdapter.this, true);
}); });
holder.spark_button_reblog.setOnClickListener(v -> { holder.spark_button_reblog.setOnClickListener(v -> {
if (!status.isReblogged() && confirmBoost) if (!status.isReblogged() && confirmBoost)
@ -658,7 +657,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
status.setBoostAnimated(true); status.setBoostAnimated(true);
notifyNotificationChanged(notification); notifyNotificationChanged(notification);
} }
CrossActions.doCrossAction(context, null, status, null, status.isReblogged() ? API.StatusAction.UNREBLOG : API.StatusAction.REBLOG, notificationsListAdapter, NotificationsListAdapter.this, true); CrossActions.doCrossAction(context, null, status, null, status.isReblogged() ? API.StatusAction.UNREBLOG : API.StatusAction.REBLOG, notificationsListAdapter, BaseNotificationsListAdapter.this, true);
}); });
//Spoiler opens //Spoiler opens
@ -722,7 +721,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
if (!status.getVisibility().equals("direct")) if (!status.getVisibility().equals("direct"))
holder.spark_button_fav.setOnLongClickListener(view -> { holder.spark_button_fav.setOnLongClickListener(view -> {
CrossActions.doCrossAction(context, null, status, null, status.isFavourited() ? API.StatusAction.UNFAVOURITE : API.StatusAction.FAVOURITE, notificationsListAdapter, NotificationsListAdapter.this, false); CrossActions.doCrossAction(context, null, status, null, status.isFavourited() ? API.StatusAction.UNFAVOURITE : API.StatusAction.FAVOURITE, notificationsListAdapter, BaseNotificationsListAdapter.this, false);
return true; return true;
}); });
if (!status.getVisibility().equals("direct")) if (!status.getVisibility().equals("direct"))
@ -732,7 +731,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
}); });
if (!status.getVisibility().equals("direct")) if (!status.getVisibility().equals("direct"))
holder.spark_button_reblog.setOnLongClickListener(view -> { holder.spark_button_reblog.setOnLongClickListener(view -> {
CrossActions.doCrossAction(context, null, status, null, status.isReblogged() ? API.StatusAction.UNREBLOG : API.StatusAction.REBLOG, notificationsListAdapter, NotificationsListAdapter.this, false); CrossActions.doCrossAction(context, null, status, null, status.isReblogged() ? API.StatusAction.UNREBLOG : API.StatusAction.REBLOG, notificationsListAdapter, BaseNotificationsListAdapter.this, false);
return true; return true;
}); });
} else { } else {
@ -859,7 +858,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
doAction = API.StatusAction.UNMUTE_CONVERSATION; doAction = API.StatusAction.UNMUTE_CONVERSATION;
else else
doAction = API.StatusAction.MUTE_CONVERSATION; doAction = API.StatusAction.MUTE_CONVERSATION;
new PostActionAsyncTask(context, doAction, status.getId(), NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new PostActionAsyncTask(context, doAction, status.getId(), BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return true; return true;
case R.id.action_open_browser: case R.id.action_open_browser:
Helper.openBrowser(context, status.getUrl()); Helper.openBrowser(context, status.getUrl());
@ -873,11 +872,8 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
context.startActivity(intent); context.startActivity(intent);
return true; return true;
case R.id.action_stats: case R.id.action_stats:
intent = new Intent(context, OwnerNotificationChartsActivity.class); notificationStatusChart();
b = new Bundle();
b.putString("status_id", status.getReblog() != null ? status.getReblog().getId() : status.getId());
intent.putExtras(b);
context.startActivity(intent);
return true; return true;
case R.id.action_info: case R.id.action_info:
intent = new Intent(context, TootInfoActivity.class); intent = new Intent(context, TootInfoActivity.class);
@ -985,15 +981,15 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
if (doAction == API.StatusAction.UNSTATUS) { if (doAction == API.StatusAction.UNSTATUS) {
String targetedId = status.getId(); String targetedId = status.getId();
new PostActionAsyncTask(context, doAction, targetedId, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new PostActionAsyncTask(context, doAction, targetedId, BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else if (doAction == API.StatusAction.REPORT) { } else if (doAction == API.StatusAction.REPORT) {
String comment = null; String comment = null;
if (finalInput.getText() != null) if (finalInput.getText() != null)
comment = finalInput.getText().toString(); comment = finalInput.getText().toString();
new PostActionAsyncTask(context, doAction, status.getId(), status, comment, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new PostActionAsyncTask(context, doAction, status.getId(), status, comment, BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else { } else {
String targetedId = status.getAccount().getId(); String targetedId = status.getAccount().getId();
new PostActionAsyncTask(context, doAction, targetedId, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new PostActionAsyncTask(context, doAction, targetedId, BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
dialog.dismiss(); dialog.dismiss();
}); });
@ -1066,7 +1062,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
} }
private Notification getItemAt(int position) { protected Notification getItemAt(int position) {
if (notifications.size() > position) if (notifications.size() > position)
return notifications.get(position); return notifications.get(position);
else else
@ -1093,9 +1089,9 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
}).setPositiveButton(R.string.yes, (dialog13, id) -> { }).setPositiveButton(R.string.yes, (dialog13, id) -> {
if (seletedItems.size() > 0) if (seletedItems.size() > 0)
new PostNotificationsAsyncTask(context, null, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new PostNotificationsAsyncTask(context, null, BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else else
new PostNotificationsAsyncTask(context, notification.getId(), NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new PostNotificationsAsyncTask(context, notification.getId(), BaseNotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog13.dismiss(); dialog13.dismiss();
}).setNegativeButton(R.string.cancel, (dialog12, id) -> dialog12.dismiss()).create(); }).setNegativeButton(R.string.cancel, (dialog12, id) -> dialog12.dismiss()).create();
dialog.show(); dialog.show();
@ -1418,4 +1414,5 @@ public class NotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.
} }
} }
protected abstract void notificationStatusChart();
} }

View File

@ -234,8 +234,11 @@ import static app.fedilab.android.activities.BaseMainActivity.regex_home;
import static app.fedilab.android.activities.BaseMainActivity.regex_local; import static app.fedilab.android.activities.BaseMainActivity.regex_local;
import static app.fedilab.android.activities.BaseMainActivity.regex_public; import static app.fedilab.android.activities.BaseMainActivity.regex_public;
import static app.fedilab.android.activities.BaseMainActivity.social; import static app.fedilab.android.activities.BaseMainActivity.social;
import static app.fedilab.android.helper.BaseHelper.NotifType.MENTION;
import static app.fedilab.android.helper.ThemeHelper.getAttColor;
import static app.fedilab.android.sqlite.StatusCacheDAO.ARCHIVE_CACHE; import static app.fedilab.android.sqlite.StatusCacheDAO.ARCHIVE_CACHE;
import static app.fedilab.android.sqlite.StatusCacheDAO.BOOKMARK_CACHE; import static app.fedilab.android.sqlite.StatusCacheDAO.BOOKMARK_CACHE;
import static app.fedilab.android.webview.ProxyHelper.setProxy;
import static com.koushikdutta.async.util.StreamUtility.copyStream; import static com.koushikdutta.async.util.StreamUtility.copyStream;
@ -1663,7 +1666,7 @@ public class BaseHelper {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int l_c = prefs.getInt("theme_link_color", -1); int l_c = prefs.getInt("theme_link_color", -1);
if (l_c == -1) { if (l_c == -1) {
l_c = ThemegetAttColor(context, R.attr.linkColor); l_c = getAttColor(context, R.attr.linkColor);
} }
final int link_color = l_c; final int link_color = l_c;
SpannableString spannableString = new SpannableString(cw_mention); SpannableString spannableString = new SpannableString(cw_mention);
@ -2112,7 +2115,7 @@ public class BaseHelper {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int l_c = prefs.getInt("theme_link_color", -1); int l_c = prefs.getInt("theme_link_color", -1);
if (l_c == -1) { if (l_c == -1) {
l_c = ThemegetAttColor(context, R.attr.linkColor); l_c = getAttColor(context, R.attr.linkColor);
} }
final int link_color = l_c; final int link_color = l_c;
while (matcher.find()) { while (matcher.find()) {
@ -2294,7 +2297,7 @@ public class BaseHelper {
if (proxyEnabled) { if (proxyEnabled) {
String host = sharedpreferences.getString(SET_PROXY_HOST, "127.0.0.1"); String host = sharedpreferences.getString(SET_PROXY_HOST, "127.0.0.1");
int port = sharedpreferences.getInt(SET_PROXY_PORT, 8118); int port = sharedpreferences.getInt(SET_PROXY_PORT, 8118);
ProxysetProxy(activity, webView, host, port, WebviewActivity.class.getName()); setProxy(activity, webView, host, port, WebviewActivity.class.getName());
} }
return webView; return webView;