Merge branch 'develop'

This commit is contained in:
Thomas 2022-12-03 18:44:07 +01:00
commit 7ada093a0f
291 changed files with 3855 additions and 4823 deletions

View file

@ -8,13 +8,13 @@ plugins {
}
def flavor
android {
compileSdk 31
compileSdk 32
defaultConfig {
minSdk 21
targetSdk 31
versionCode 433
versionName "3.8.0"
targetSdk 32
versionCode 437
versionName "3.9.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
flavorDimensions "default"
@ -78,8 +78,8 @@ allprojects {
}
dependencies {
implementation project(':autoimageslider')
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "com.google.code.gson:gson:2.9.1"
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
@ -88,12 +88,11 @@ dependencies {
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.preference:preference:1.2.0'
implementation "org.conscrypt:conscrypt-android:2.5.2"
implementation 'com.github.evozi:Cyanea:1.0.7'
implementation 'com.vanniktech:emoji-one:0.6.0'
implementation 'com.github.GrenderG:Toasty:1.5.2'
implementation 'org.framagit.tom79:SparkButton:1.0.13'
implementation "com.github.bumptech.glide:glide:4.12.0"
implementation "com.github.bumptech.glide:okhttp3-integration:4.12.0"
implementation "com.github.bumptech.glide:glide:4.14.2"
implementation "com.github.bumptech.glide:okhttp3-integration:4.14.2"
implementation "org.jsoup:jsoup:1.15.1"
@ -102,12 +101,11 @@ dependencies {
implementation project(path: ':ratethisapp')
implementation 'com.burhanrashid52:photoeditor:1.5.1'
implementation project(path: ':cropper')
annotationProcessor "com.github.bumptech.glide:compiler:4.12.0"
implementation 'jp.wasabeef:glide-transformations:4.3.0'
implementation 'com.github.penfeizhou.android.animation:glide-plugin:2.22.0'
implementation 'com.github.penfeizhou.android.animation:glide-plugin:2.24.0'
implementation 'com.google.android.exoplayer:exoplayer:2.18.1'
implementation "androidx.viewpager2:viewpager2:1.0.0"
implementation 'com.github.piasy:rxandroidaudio:1.7.0'
@ -118,11 +116,10 @@ dependencies {
implementation "ch.acra:acra-mail:5.9.6"
implementation "ch.acra:acra-limiter:5.9.3"
implementation "ch.acra:acra-dialog:5.9.6"
implementation "com.madgag.spongycastle:bctls-jdk15on:1.58.0.0"
implementation 'com.github.UnifiedPush:android-connector:2.0.1'
// implementation 'com.github.UnifiedPush:android-foss_embedded_fcm_distributor:1.0.0-beta1'
playstoreImplementation ('com.github.UnifiedPush:android-embedded_fcm_distributor:2.1.3') {
playstoreImplementation('com.github.UnifiedPush:android-embedded_fcm_distributor:2.1.3') {
exclude group: 'com.google.firebase', module: 'firebase-core'
exclude group: 'com.google.firebase', module: 'firebase-analytics'
exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
@ -132,12 +129,12 @@ dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
implementation 'androidx.lifecycle:lifecycle-livedata:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.5.1'
implementation 'androidx.navigation:navigation-fragment:2.5.1'
implementation 'androidx.navigation:navigation-ui:2.5.1'
implementation 'androidx.navigation:navigation-fragment:2.5.3'
implementation 'androidx.navigation:navigation-ui:2.5.3'
testImplementation 'junit:junit:'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}

View file

@ -30,7 +30,7 @@
android:roundIcon="@mipmap/ic_launcher_bubbles_round"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
android:theme="@style/AppThemeDark"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:replace="android:allowBackup">
@ -166,9 +166,6 @@
android:scheme="fedilab" />
</intent-filter>
</activity>
<activity
android:name=".activities.WebviewConnectActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".activities.StatusHistoryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
@ -193,9 +190,6 @@
<activity
android:name=".activities.FollowRequestActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".activities.WebviewActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".activities.ProfileActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
@ -243,6 +237,7 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/action_about"
android:theme="@style/AppThemeBar" />
<activity
android:name=".activities.admin.AdminDomainBlockActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
@ -287,15 +282,15 @@
android:name=".activities.InstanceActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/action_about_instance"
android:theme="@style/DialogDark" />
android:theme="@style/AppThemeAlertDialog" />
<activity
android:name=".activities.InstanceProfileActivity"
android:excludeFromRecents="true"
android:theme="@style/DialogDark" />
android:theme="@style/AppThemeAlertDialog" />
<activity
android:name=".activities.ProxyActivity"
android:excludeFromRecents="true"
android:theme="@style/DialogDark" />
android:theme="@style/AppThemeAlertDialog" />
<activity
android:name=".activities.HashTagActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
@ -305,38 +300,38 @@
<activity
android:name=".activities.MediaActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/TransparentDark" />
android:theme="@style/Transparent" />
<activity
android:name=".activities.InstanceHealthActivity"
android:excludeFromRecents="true"
android:theme="@style/DialogDark" />
android:theme="@style/AppThemeAlertDialog" />
<activity
android:name=".activities.ReportActivity"
android:theme="@style/AppThemeBarDark"
android:theme="@style/AppThemeBar"
android:windowSoftInputMode="stateVisible" />
<activity
android:name=".activities.CustomSharingActivity"
android:label="@string/settings_title_custom_sharing"
android:theme="@style/AppThemeBarDark"
android:theme="@style/AppThemeBar"
android:windowSoftInputMode="stateVisible" />
<activity
android:name=".activities.FilterActivity"
android:label="@string/filters"
android:theme="@style/AppThemeBarDark"
android:theme="@style/AppThemeBar"
android:windowSoftInputMode="stateVisible" />
<activity
android:name=".activities.EditProfileActivity"
android:label="@string/edit_profile"
android:theme="@style/AppThemeBarDark"
android:theme="@style/AppThemeBar"
android:windowSoftInputMode="stateVisible" />
<activity
android:name=".activities.CacheActivity"
android:label="@string/action_cache"
android:theme="@style/AppThemeBarDark" />
android:theme="@style/AppThemeBar" />
<provider
android:name="androidx.core.content.FileProvider"

View file

@ -1,4 +1,24 @@
[
{
"version": "3.9.2",
"code": "437",
"note": "Added:\n- New design with 5 themes\n\nChanged:\n- Remove built-in browser support\n- Fit preview image displays images vertically\n- Add counters next to images\n\nFixed:\n- Jumps in timelines\n- Replies to wrong messages with followed instances\n- Bug with delete&redraft with a media\n- List cannot be hidden\n- Some crashes"
},
{
"version": "3.9.1",
"code": "436",
"note": "Changed:\n- Remove built-in browser support\n- More spaces between action buttons in messages\n\nFixed:\n- Text size issue\n- Text overlap\n- Wrong background for solarized black\n- Mix between light and dark theme\n- Save button hidden"
},
{
"version": "3.9.0",
"code": "435",
"note": "Added:\n- Migrate to Material Design 3\n- 5 Themes (Light, Dark, Solarized Light/Dark, Black)\n- Automatically switch between Light/Dark\n- Light and Dark theme can be defined for time-based switch\n- Android 12+: Dynamic color\n\nFixed:\n- Jumps in timelines\n"
},
{
"version": "3.8.1",
"code": "434",
"note": "Added:\n- Mute tags with long press in timelines\n\nChanged:\n- Muted account messages are now removed from cache\n\nFixed:\n- Open with another account\n- Fix jumps in profiles\n- Media not displayed in album -> force indexation\n- Built-in browser does not give admin scope\n- Some crashes"
},
{
"version": "3.8.0",
"code": "433",

View file

@ -28,7 +28,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
@ -39,7 +38,7 @@ import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.ContextThemeWrapper;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
@ -59,7 +58,6 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.SearchView;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
@ -77,7 +75,6 @@ import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;
import com.jaredrummler.cyanea.Cyanea;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
@ -85,6 +82,7 @@ import org.jsoup.nodes.Element;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -129,7 +127,6 @@ import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.client.entities.app.Account;
import app.fedilab.android.client.entities.app.BaseAccount;
import app.fedilab.android.client.entities.app.BottomMenu;
import app.fedilab.android.client.entities.app.DomainsBlock;
import app.fedilab.android.client.entities.app.Pinned;
import app.fedilab.android.client.entities.app.PinnedTimeline;
import app.fedilab.android.client.entities.app.StatusCache;
@ -143,7 +140,6 @@ import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.PinnedTimelineHelper;
import app.fedilab.android.helper.PushHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonConversation;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;
import app.fedilab.android.ui.fragment.timeline.FragmentNotificationContainer;
@ -195,9 +191,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
intentCompose.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentCompose);
})
.setTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor))
.setActionTextColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference))
.setBackgroundTint(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_primary_dark_reference))
.show();
}
}
@ -259,7 +252,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
});
}
} else if (b.getBoolean(Helper.RECEIVE_RECREATE_ACTIVITY, false)) {
Cyanea.getInstance().edit().apply().recreate(BaseMainActivity.this);
recreate();
} else if (b.getBoolean(Helper.RECEIVE_NEW_MESSAGE, false)) {
Status statusSent = (Status) b.getSerializable(Helper.RECEIVE_STATUS_ACTION);
String statusEditId = b.getString(Helper.ARG_EDIT_STATUS_ID, null);
@ -270,9 +263,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentContext);
})
.setTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor))
.setActionTextColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference))
.setBackgroundTint(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_primary_dark_reference))
.show();
//The message was edited, we need to update the timeline
if (statusEditId != null) {
@ -303,7 +293,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this);
ThemeHelper.applyTheme(this);
if (!Helper.isLoggedIn(BaseMainActivity.this)) {
//It is not, the user is redirected to the login page
Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class);
@ -314,9 +303,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
BaseMainActivity.currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null);
}
mamageNewIntent(getIntent());
ThemeHelper.initiliazeColors(BaseMainActivity.this);
filterFetched = false;
networkStateReceiver = new NetworkStateReceiver();
networkStateReceiver.addListener(this);
@ -329,13 +316,10 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
actionBar.setDisplayShowTitleEnabled(false);
}
rateThisApp();
SharedPreferences cyneaPref = getSharedPreferences("com.jaredrummler.cyanea", Context.MODE_PRIVATE);
binding.tabLayout.setTabTextColors(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor), cyneaPref.getInt("theme_accent", -1));
binding.tabLayout.setTabIconTint(ThemeHelper.getColorStateList(BaseMainActivity.this));
binding.compose.setOnClickListener(v -> startActivity(new Intent(this, ComposeActivity.class)));
headerMenuOpen = false;
binding.bottomNavView.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
binding.navView.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
// Passing each menu ID as a set of Ids because each
@ -537,7 +521,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
});
headerMainBinding.headerOptionInfo.setOnClickListener(v -> {
PopupMenu popup = new PopupMenu(new ContextThemeWrapper(BaseMainActivity.this, Helper.popupStyle()), headerMainBinding.headerOptionInfo);
PopupMenu popup = new PopupMenu(BaseMainActivity.this, headerMainBinding.headerOptionInfo);
popup.getMenuInflater()
.inflate(R.menu.main, popup.getMenu());
@ -586,7 +570,10 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
}
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (currentAccount == null || currentAccount.mastodon_account == null) {
if (currentToken == null) {
currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null);
}
if (currentAccount == null) {
//It is not, the user is redirected to the login page
Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class);
startActivity(myIntent);
@ -659,9 +646,16 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
if (currentAccount.mastodon_account.display_name == null || currentAccount.mastodon_account.display_name.isEmpty()) {
currentAccount.mastodon_account.display_name = currentAccount.mastodon_account.acct;
}
headerMainBinding.accountName.setText(currentAccount.mastodon_account.display_name);
headerMainBinding.accountName.setText(
currentAccount.mastodon_account.getSpanDisplayName(BaseMainActivity.this,
new WeakReference<>(headerMainBinding.accountName)),
TextView.BufferType.SPANNABLE);
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
headerMainBinding.accountName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
headerMainBinding.accountAcc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
Helper.loadPP(BaseMainActivity.this, headerMainBinding.accountProfilePicture, currentAccount, false);
MastodonHelper.loadProfileMediaMastodon(headerMainBinding.backgroundImage, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER);
MastodonHelper.loadProfileMediaMastodon(BaseMainActivity.this, headerMainBinding.backgroundImage, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER);
headerMainBinding.backgroundImage.setAlpha(0.5f);
/*
* Some general data are loaded when the app starts such;
* - Pinned timelines (in app feature)
@ -762,10 +756,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
}
}).start();
}
boolean embedded_browser = sharedpreferences.getBoolean(getString(R.string.SET_EMBEDDED_BROWSER), true);
if (embedded_browser) {
DomainsBlock.updateDomains(BaseMainActivity.this);
}
}
protected abstract void rateThisApp();
@ -1120,7 +1110,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
view = binding.bottomNavView.findViewById(R.id.nav_public);
showExtendedFilter = false;
}
PopupMenu popup = new PopupMenu(new ContextThemeWrapper(BaseMainActivity.this, Helper.popupStyle()), view, Gravity.TOP);
PopupMenu popup = new PopupMenu(BaseMainActivity.this, view, Gravity.TOP);
popup.getMenuInflater()
.inflate(R.menu.option_filter_toots, popup.getMenu());
Menu menu = popup.getMenu();
@ -1266,8 +1256,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
if (!singleBar) {
if (count > 0) {
binding.bottomNavView.getOrCreateBadge(R.id.nav_privates).setNumber(count);
binding.bottomNavView.getBadge(R.id.nav_privates).setBackgroundColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference));
binding.bottomNavView.getBadge(R.id.nav_privates).setBadgeTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor));
} else {
binding.bottomNavView.removeBadge(R.id.nav_privates);
}
@ -1286,8 +1274,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
if (!singleBar) {
if (count > 0) {
binding.bottomNavView.getOrCreateBadge(R.id.nav_notifications).setNumber(count);
binding.bottomNavView.getBadge(R.id.nav_notifications).setBackgroundColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference));
binding.bottomNavView.getBadge(R.id.nav_notifications).setBadgeTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor));
} else {
binding.bottomNavView.removeBadge(R.id.nav_notifications);
}
@ -1352,8 +1338,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
case HOME:
if (count > 0) {
binding.bottomNavView.getOrCreateBadge(R.id.nav_home).setNumber(count);
binding.bottomNavView.getBadge(R.id.nav_home).setBackgroundColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference));
binding.bottomNavView.getBadge(R.id.nav_home).setBadgeTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor));
} else {
binding.bottomNavView.removeBadge(R.id.nav_home);
}
@ -1361,8 +1345,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
case LOCAL:
if (count > 0) {
binding.bottomNavView.getOrCreateBadge(R.id.nav_local).setNumber(count);
binding.bottomNavView.getBadge(R.id.nav_local).setBackgroundColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference));
binding.bottomNavView.getBadge(R.id.nav_local).setBadgeTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor));
} else {
binding.bottomNavView.removeBadge(R.id.nav_local);
}
@ -1370,8 +1352,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
case PUBLIC:
if (count > 0) {
binding.bottomNavView.getOrCreateBadge(R.id.nav_public).setNumber(count);
binding.bottomNavView.getBadge(R.id.nav_public).setBackgroundColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference));
binding.bottomNavView.getBadge(R.id.nav_public).setBadgeTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor));
} else {
binding.bottomNavView.removeBadge(R.id.nav_public);
}
@ -1379,8 +1359,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
case NOTIFICATION:
if (count > 0) {
binding.bottomNavView.getOrCreateBadge(R.id.nav_notifications).setNumber(count);
binding.bottomNavView.getBadge(R.id.nav_notifications).setBackgroundColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference));
binding.bottomNavView.getBadge(R.id.nav_notifications).setBadgeTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor));
} else {
binding.bottomNavView.removeBadge(R.id.nav_notifications);
}
@ -1388,8 +1366,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
case DIRECT:
if (count > 0) {
binding.bottomNavView.getOrCreateBadge(R.id.nav_privates).setNumber(count);
binding.bottomNavView.getBadge(R.id.nav_privates).setBackgroundColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference));
binding.bottomNavView.getBadge(R.id.nav_privates).setBadgeTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor));
} else {
binding.bottomNavView.removeBadge(R.id.nav_privates);
}

View file

@ -23,8 +23,7 @@ import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;
import androidx.preference.PreferenceManager;
import com.jaredrummler.cyanea.Cyanea;
import com.jaredrummler.cyanea.prefs.CyaneaTheme;
import com.google.android.material.color.DynamicColors;
import org.acra.ACRA;
import org.acra.ReportField;
@ -33,8 +32,7 @@ import org.acra.config.DialogConfigurationBuilder;
import org.acra.config.MailSenderConfigurationBuilder;
import org.acra.data.StringFormat;
import java.util.List;
import app.fedilab.android.helper.ThemeHelper;
import es.dmoral.toasty.Toasty;
@ -47,26 +45,19 @@ public class MainApplication extends MultiDexApplication {
return app;
}
@Override
public void onCreate() {
super.onCreate();
app = this;
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MainApplication.this);
Cyanea.init(this, super.getResources());
List<CyaneaTheme> list = CyaneaTheme.Companion.from(getAssets(), "themes/cyanea_themes.json");
boolean custom_theme = sharedpreferences.getBoolean("use_custom_theme", false);
boolean no_theme_set = sharedpreferences.getBoolean("no_theme_set", true);
if (no_theme_set && !custom_theme) {
list.get(0).apply(Cyanea.getInstance());
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean("no_theme_set", false);
editor.apply();
boolean dynamicColor = sharedpreferences.getBoolean(getString(R.string.SET_DYNAMICCOLOR), false);
if (dynamicColor) {
DynamicColors.applyToActivitiesIfAvailable(this);
}
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
Toasty.Config.getInstance().apply();
}
@ -76,6 +67,8 @@ public class MainApplication extends MultiDexApplication {
MultiDex.install(MainApplication.this);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MainApplication.this);
boolean send_crash_reports = sharedpreferences.getBoolean(getString(R.string.SET_SEND_CRASH_REPORTS), false);
String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME));
ThemeHelper.switchTo(currentTheme);
if (send_crash_reports) {
ACRA.init(this, new CoreConfigurationBuilder()
//core configuration:
@ -92,7 +85,6 @@ public class MainApplication extends MultiDexApplication {
.withResIcon(R.mipmap.ic_launcher)
.withText(getString(R.string.crash_title))
.withCommentPrompt(getString(R.string.crash_message))
.withResTheme(R.style.DialogDark)
.withPositiveButtonText(getString(R.string.send_email))
.withNegativeButtonText(getString(R.string.cancel))
.build()

View file

@ -18,13 +18,11 @@ package app.fedilab.android.activities;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import java.util.ArrayList;
@ -39,11 +37,10 @@ import app.fedilab.android.databinding.ActivityAboutBinding;
import app.fedilab.android.helper.CrossActionHelper;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
public class AboutActivity extends BaseActivity {
public class AboutActivity extends BaseBarActivity {
private ActivityAboutBinding binding;
@ -52,13 +49,12 @@ public class AboutActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivityAboutBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
try {
@ -79,13 +75,12 @@ public class AboutActivity extends BaseActivity {
}
binding.aboutSupportPaypal.setOnClickListener(v -> Helper.openBrowser(AboutActivity.this, "https://www.paypal.me/Mastalab"));
binding.accountFollow.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(AboutActivity.this));
if (BuildConfig.DONATIONS) {
binding.aboutSupportPaypal.setVisibility(View.VISIBLE);
} else {
binding.aboutSupportPaypal.setVisibility(View.GONE);
}
binding.accountFollow.setImageResource(R.drawable.ic_baseline_person_add_24);
binding.accountFollow.setIconResource(R.drawable.ic_baseline_person_add_24);
binding.aboutWebsite.setOnClickListener(v -> Helper.openBrowser(AboutActivity.this, "https://fedilab.app"));
CrossActionHelper.fetchRemoteAccount(AboutActivity.this, "@apps@toot.fedilab.app", new CrossActionHelper.Callback() {
@Override

View file

@ -17,14 +17,12 @@ package app.fedilab.android.activities;
import android.app.Activity;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -41,7 +39,7 @@ import app.fedilab.android.ui.drawer.StatusReportAdapter;
import app.fedilab.android.viewmodel.mastodon.AdminVM;
import es.dmoral.toasty.Toasty;
public class AccountReportActivity extends BaseActivity {
public class AccountReportActivity extends BaseBarActivity {
private String account_id;
@ -52,13 +50,12 @@ public class AccountReportActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivityAdminReportBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
report = null;
@ -70,8 +67,8 @@ public class AccountReportActivity extends BaseActivity {
report = (AdminReport) b.getSerializable(Helper.ARG_REPORT);
}
binding.allow.getBackground().setColorFilter(ContextCompat.getColor(AccountReportActivity.this, R.color.green_1), PorterDuff.Mode.MULTIPLY);
binding.reject.getBackground().setColorFilter(ContextCompat.getColor(AccountReportActivity.this, R.color.red_1), PorterDuff.Mode.MULTIPLY);
binding.allow.getBackground().setColorFilter(ThemeHelper.getAttColor(this, R.attr.colorPrimary), PorterDuff.Mode.MULTIPLY);
binding.reject.getBackground().setColorFilter(ThemeHelper.getAttColor(this, R.attr.colorError), PorterDuff.Mode.MULTIPLY);
if (account_id == null && report == null && targeted_account == null) {

View file

@ -14,12 +14,10 @@ package app.fedilab.android.activities;
* 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.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
@ -32,7 +30,7 @@ import app.fedilab.android.ui.fragment.timeline.FragmentMastodonAccount;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonDomainBlock;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;
public class ActionActivity extends BaseActivity {
public class ActionActivity extends BaseBarActivity {
private ActivityActionsBinding binding;
private boolean canGoBack;
@ -43,13 +41,12 @@ public class ActionActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivityActionsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
canGoBack = false;
binding.favourites.setOnClickListener(v -> displayTimeline(Timeline.TimeLineEnum.FAVOURITE_TIMELINE));

View file

@ -19,13 +19,11 @@ import static app.fedilab.android.BaseMainActivity.currentInstance;
import static app.fedilab.android.BaseMainActivity.emojis;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.MenuItem;
import androidx.appcompat.app.ActionBar;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import app.fedilab.android.R;
@ -33,7 +31,6 @@ import app.fedilab.android.client.entities.api.EmojiInstance;
import app.fedilab.android.databinding.ActivityAnnouncementBinding;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonAnnouncement;
@ -43,7 +40,7 @@ public class AnnouncementActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
ActivityAnnouncementBinding binding = ActivityAnnouncementBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
@ -53,7 +50,6 @@ public class AnnouncementActivity extends BaseActivity {
//Remove title
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
binding.title.setText(R.string.action_announcements);
if (getSupportActionBar() != null) {

View file

@ -16,20 +16,29 @@ package app.fedilab.android.activities;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceManager;
import com.jaredrummler.cyanea.app.CyaneaAppCompatActivity;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.one.EmojiOneProvider;
import app.fedilab.android.R;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
@SuppressLint("Registered")
public class BaseActivity extends CyaneaAppCompatActivity {
public class BaseActivity extends AppCompatActivity {
public static int currentThemeId;
static {
Helper.installProvider();
@ -38,9 +47,89 @@ public class BaseActivity extends CyaneaAppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME));
//Default automatic switch
if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) {
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
case Configuration.UI_MODE_NIGHT_NO:
String defaultLight = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_LIGHT), "LIGHT");
switch (defaultLight) {
case "LIGHT":
setTheme(R.style.AppTheme);
currentThemeId = R.style.AppTheme;
break;
case "SOLARIZED_LIGHT":
setTheme(R.style.SolarizedAppTheme);
currentThemeId = R.style.SolarizedAppTheme;
break;
}
break;
case Configuration.UI_MODE_NIGHT_YES:
String defaultDark = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_DARK), "DARK");
switch (defaultDark) {
case "DARK":
setTheme(R.style.AppTheme);
currentThemeId = R.style.AppTheme;
break;
case "SOLARIZED_DARK":
setTheme(R.style.SolarizedAppTheme);
currentThemeId = R.style.SolarizedAppTheme;
break;
case "BLACK":
setTheme(R.style.BlackAppTheme);
currentThemeId = R.style.BlackAppTheme;
break;
}
break;
}
} else {
switch (currentTheme) {
case "LIGHT":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
setTheme(R.style.AppTheme);
currentThemeId = R.style.AppTheme;
break;
case "DARK":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.AppTheme);
currentThemeId = R.style.AppTheme;
break;
case "SOLARIZED_LIGHT":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
setTheme(R.style.SolarizedAppTheme);
currentThemeId = R.style.SolarizedAppTheme;
break;
case "SOLARIZED_DARK":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.SolarizedAppTheme);
currentThemeId = R.style.SolarizedAppTheme;
break;
case "BLACK":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.BlackAppTheme);
currentThemeId = R.style.BlackAppTheme;
break;
}
}
super.onCreate(savedInstanceState);
ThemeHelper.adjustFontScale(this, getResources().getConfiguration());
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
ThemeHelper.adjustFontScale(this, getResources().getConfiguration());
}
Helper.setLocale(this);
}
@Override
protected void attachBaseContext(Context newBase) {
if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
final Configuration override = new Configuration(newBase.getResources().getConfiguration());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(newBase);
override.fontScale = prefs.getFloat(newBase.getString(R.string.SET_FONT_SCALE), 1.1f);
applyOverrideConfiguration(override);
}
super.attachBaseContext(newBase);
}
}

View file

@ -0,0 +1,123 @@
package app.fedilab.android.activities;
/* Copyright 2021 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.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceManager;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.one.EmojiOneProvider;
import app.fedilab.android.R;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
@SuppressLint("Registered")
public class BaseAlertDialogActivity extends AppCompatActivity {
static {
Helper.installProvider();
EmojiManager.install(new EmojiOneProvider());
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME));
//Default automatic switch
if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) {
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
case Configuration.UI_MODE_NIGHT_NO:
String defaultLight = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_LIGHT), "LIGHT");
switch (defaultLight) {
case "LIGHT":
setTheme(R.style.AppThemeAlertDialog);
break;
case "SOLARIZED_LIGHT":
setTheme(R.style.SolarizedAlertDialog);
break;
}
break;
case Configuration.UI_MODE_NIGHT_YES:
String defaultDark = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_DARK), "DARK");
switch (defaultDark) {
case "DARK":
setTheme(R.style.AppThemeAlertDialog);
break;
case "SOLARIZED_DARK":
setTheme(R.style.SolarizedAlertDialog);
break;
case "BLACK":
setTheme(R.style.BlackAlertDialog);
break;
}
break;
}
} else {
switch (currentTheme) {
case "LIGHT":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
setTheme(R.style.AppThemeAlertDialog);
break;
case "DARK":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.AppThemeAlertDialog);
break;
case "SOLARIZED_LIGHT":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
setTheme(R.style.SolarizedAlertDialog);
break;
case "SOLARIZED_DARK":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.SolarizedAlertDialog);
break;
case "BLACK":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.BlackAlertDialog);
break;
}
}
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
ThemeHelper.adjustFontScale(this, getResources().getConfiguration());
}
Helper.setLocale(this);
}
@Override
protected void attachBaseContext(Context newBase) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
final Configuration override = new Configuration(newBase.getResources().getConfiguration());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(newBase);
override.fontScale = prefs.getFloat(newBase.getString(R.string.SET_FONT_SCALE), 1.1f);
applyOverrideConfiguration(override);
}
super.attachBaseContext(newBase);
}
}

View file

@ -0,0 +1,126 @@
package app.fedilab.android.activities;
/* Copyright 2022 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.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceManager;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.one.EmojiOneProvider;
import app.fedilab.android.R;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
@SuppressLint("Registered")
public class BaseBarActivity extends AppCompatActivity {
static {
Helper.installProvider();
EmojiManager.install(new EmojiOneProvider());
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME));
//Default automatic switch
if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) {
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
case Configuration.UI_MODE_NIGHT_NO:
String defaultLight = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_LIGHT), "LIGHT");
switch (defaultLight) {
case "LIGHT":
setTheme(R.style.AppThemeBar);
break;
case "SOLARIZED_LIGHT":
setTheme(R.style.SolarizedAppThemeBar);
break;
}
break;
case Configuration.UI_MODE_NIGHT_YES:
String defaultDark = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_DARK), "DARK");
switch (defaultDark) {
case "DARK":
setTheme(R.style.AppThemeBar);
break;
case "SOLARIZED_DARK":
setTheme(R.style.SolarizedAppThemeBar);
break;
case "BLACK":
setTheme(R.style.BlackAppThemeBar);
break;
}
break;
}
} else {
switch (currentTheme) {
case "LIGHT":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
setTheme(R.style.AppThemeBar);
break;
case "DARK":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.AppThemeBar);
break;
case "SOLARIZED_LIGHT":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
setTheme(R.style.SolarizedAppThemeBar);
break;
case "SOLARIZED_DARK":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.SolarizedAppThemeBar);
break;
case "BLACK":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.BlackAppThemeBar);
break;
}
}
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
ThemeHelper.adjustFontScale(this, getResources().getConfiguration());
}
Helper.setLocale(this);
}
@Override
protected void attachBaseContext(Context newBase) {
if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
final Configuration override = new Configuration(newBase.getResources().getConfiguration());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(newBase);
override.fontScale = prefs.getFloat(newBase.getString(R.string.SET_FONT_SCALE), 1.1f);
applyOverrideConfiguration(override);
}
super.attachBaseContext(newBase);
}
}

View file

@ -16,7 +16,8 @@ package app.fedilab.android.activities;
import android.annotation.SuppressLint;
import com.jaredrummler.cyanea.app.CyaneaFragmentActivity;
import androidx.fragment.app.FragmentActivity;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.one.EmojiOneProvider;
@ -24,7 +25,7 @@ import app.fedilab.android.helper.Helper;
@SuppressLint("Registered")
public class BaseFragmentActivity extends CyaneaFragmentActivity {
public class BaseFragmentActivity extends FragmentActivity {
static {

View file

@ -0,0 +1,126 @@
package app.fedilab.android.activities;
/* Copyright 2022 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.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceManager;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.one.EmojiOneProvider;
import app.fedilab.android.R;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
@SuppressLint("Registered")
public class BaseTransparentActivity extends AppCompatActivity {
static {
Helper.installProvider();
EmojiManager.install(new EmojiOneProvider());
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME));
//Default automatic switch
if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) {
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
case Configuration.UI_MODE_NIGHT_NO:
String defaultLight = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_LIGHT), "LIGHT");
switch (defaultLight) {
case "LIGHT":
setTheme(R.style.Transparent);
break;
case "SOLARIZED_LIGHT":
setTheme(R.style.TransparentSolarized);
break;
}
break;
case Configuration.UI_MODE_NIGHT_YES:
String defaultDark = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_DARK), "DARK");
switch (defaultDark) {
case "DARK":
setTheme(R.style.Transparent);
break;
case "SOLARIZED_DARK":
setTheme(R.style.TransparentSolarized);
break;
case "BLACK":
setTheme(R.style.TransparentBlack);
break;
}
break;
}
} else {
switch (currentTheme) {
case "LIGHT":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
setTheme(R.style.Transparent);
break;
case "DARK":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.Transparent);
break;
case "SOLARIZED_LIGHT":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
setTheme(R.style.TransparentSolarized);
break;
case "SOLARIZED_DARK":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.TransparentSolarized);
break;
case "BLACK":
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setTheme(R.style.TransparentBlack);
break;
}
}
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
ThemeHelper.adjustFontScale(this, getResources().getConfiguration());
}
Helper.setLocale(this);
}
@Override
protected void attachBaseContext(Context newBase) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
final Configuration override = new Configuration(newBase.getResources().getConfiguration());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(newBase);
override.fontScale = prefs.getFloat(newBase.getString(R.string.SET_FONT_SCALE), 1.1f);
applyOverrideConfiguration(override);
}
super.attachBaseContext(newBase);
}
}

View file

@ -15,7 +15,6 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@ -25,7 +24,6 @@ import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import java.util.ArrayList;
@ -42,10 +40,9 @@ import app.fedilab.android.databinding.ActivityCacheBinding;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.CacheHelper;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.CacheAdapter;
public class CacheActivity extends BaseActivity {
public class CacheActivity extends BaseBarActivity {
private ActivityCacheBinding binding;
private List<CacheAccount> cacheAccounts;
@ -54,12 +51,11 @@ public class CacheActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivityCacheBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
CacheHelper.getCacheValues(CacheActivity.this, size -> {
if (size > 0) {

View file

@ -28,7 +28,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -86,7 +85,6 @@ import app.fedilab.android.helper.DividerDecorationSimple;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.MediaHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.interfaces.OnDownloadInterface;
import app.fedilab.android.jobs.ComposeWorker;
import app.fedilab.android.jobs.ScheduleThreadWorker;
@ -444,7 +442,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
binding = ActivityPaginationBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
@ -454,7 +452,6 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
//Remove title
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -500,7 +497,6 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
if (sharedTitle != null && sharedSubject != null && sharedSubject.length() > sharedTitle.length()) {
sharedTitle = sharedSubject;
}
binding.toolbar.setPopupTheme(Helper.popupStyle());
//Edit a scheduled status from server
if (scheduledStatus != null) {
statusDraft = new StatusDraft();

View file

@ -20,7 +20,6 @@ import static app.fedilab.android.ui.drawer.StatusAdapter.sendAction;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@ -30,7 +29,6 @@ import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;
@ -43,7 +41,6 @@ import app.fedilab.android.databinding.ActivityConversationBinding;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonContext;
import app.fedilab.android.viewmodel.mastodon.StatusesVM;
@ -57,7 +54,7 @@ public class ContextActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
app.fedilab.android.databinding.ActivityConversationBinding binding = ActivityConversationBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
@ -65,7 +62,6 @@ public class ContextActivity extends BaseActivity {
//Remove title
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
binding.title.setText(R.string.context_conversation);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
@ -76,7 +72,6 @@ public class ContextActivity extends BaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
binding.toolbar.setPopupTheme(Helper.popupStyle());
Bundle b = getIntent().getExtras();
displayCW = sharedpreferences.getBoolean(getString(R.string.SET_EXPAND_CW), false);
Status focusedStatus = null; // or other values

View file

@ -17,7 +17,6 @@ package app.fedilab.android.activities;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -26,7 +25,6 @@ import android.text.TextUtils;
import android.view.MenuItem;
import android.widget.Toast;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import java.util.List;
@ -39,7 +37,6 @@ import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.client.entities.api.Tag;
import app.fedilab.android.databinding.ActivityCustomSharingBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.helper.customsharing.CustomSharingAsyncTask;
import app.fedilab.android.helper.customsharing.CustomSharingResponse;
import app.fedilab.android.helper.customsharing.OnCustomSharingInterface;
@ -51,7 +48,7 @@ import es.dmoral.toasty.Toasty;
* Share status metadata to remote content aggregators
*/
public class CustomSharingActivity extends BaseActivity implements OnCustomSharingInterface {
public class CustomSharingActivity extends BaseBarActivity implements OnCustomSharingInterface {
private String title, keywords, custom_sharing_url, encodedCustomSharingURL;
private String bundle_url;
@ -66,14 +63,13 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(CustomSharingActivity.this);
binding = ActivityCustomSharingBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
Bundle b = getIntent().getExtras();
status = null;

View file

@ -17,7 +17,6 @@ package app.fedilab.android.activities;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@ -30,7 +29,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -46,7 +44,6 @@ import app.fedilab.android.client.entities.app.StatusDraft;
import app.fedilab.android.databinding.ActivityDraftsBinding;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.StatusDraftAdapter;
import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
@ -62,20 +59,16 @@ public class DraftActivity extends BaseActivity implements StatusDraftAdapter.Dr
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
binding = ActivityDraftsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
//Remove title
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
}
binding.toolbar.setPopupTheme(Helper.popupStyle());
binding.title.setText(R.string.drafts);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);

View file

@ -18,7 +18,6 @@ import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.BaseMainActivity.instanceInfo;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -31,8 +30,6 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -52,11 +49,10 @@ import app.fedilab.android.databinding.ActivityEditProfileBinding;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
import es.dmoral.toasty.Toasty;
public class EditProfileActivity extends BaseActivity {
public class EditProfileActivity extends BaseBarActivity {
public static final int PICK_MEDIA_AVATAR = 5705;
public static final int PICK_MEDIA_HEADER = 5706;
@ -66,12 +62,11 @@ public class EditProfileActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivityEditProfileBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
new ViewModelProvider(EditProfileActivity.this).get(AccountsVM.class).getConnectedAccount(BaseMainActivity.currentInstance, BaseMainActivity.currentToken)
@ -89,7 +84,7 @@ public class EditProfileActivity extends BaseActivity {
@SuppressWarnings("deprecation")
private void initializeView() {
//Hydrate values
MastodonHelper.loadProfileMediaMastodon(binding.bannerPp, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER);
MastodonHelper.loadProfileMediaMastodon(EditProfileActivity.this, binding.bannerPp, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER);
MastodonHelper.loadPPMastodon(binding.accountPp, currentAccount.mastodon_account);
binding.displayName.setText(currentAccount.mastodon_account.display_name);
binding.acct.setText(String.format(Locale.getDefault(), "%s@%s", currentAccount.mastodon_account.acct, BaseMainActivity.currentInstance));
@ -183,15 +178,6 @@ public class EditProfileActivity extends BaseActivity {
}
});
ThemeHelper.changeColorOutlineButton(EditProfileActivity.this, binding.visibilityPublic);
ThemeHelper.changeColorOutlineButton(EditProfileActivity.this, binding.visibilityUnlisted);
ThemeHelper.changeColorOutlineButton(EditProfileActivity.this, binding.visibilityPrivate);
ThemeHelper.changeColorOutlineButton(EditProfileActivity.this, binding.visibilityDirect);
DrawableCompat.setTintList(DrawableCompat.wrap(binding.bot.getThumbDrawable()), ThemeHelper.getSwitchCompatThumbDrawable(EditProfileActivity.this));
DrawableCompat.setTintList(DrawableCompat.wrap(binding.discoverable.getThumbDrawable()), ThemeHelper.getSwitchCompatThumbDrawable(EditProfileActivity.this));
DrawableCompat.setTintList(DrawableCompat.wrap(binding.sensitive.getThumbDrawable()), ThemeHelper.getSwitchCompatThumbDrawable(EditProfileActivity.this));
ThemeHelper.changeColorOutlineButton(EditProfileActivity.this, binding.locked);
ThemeHelper.changeColorOutlineButton(EditProfileActivity.this, binding.unlocked);
//Actions with the activity
accountsVM = new ViewModelProvider(EditProfileActivity.this).get(AccountsVM.class);

View file

@ -15,7 +15,6 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
@ -28,7 +27,6 @@ import android.widget.Button;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
@ -44,12 +42,11 @@ import app.fedilab.android.client.entities.api.Filter;
import app.fedilab.android.databinding.ActivityFiltersBinding;
import app.fedilab.android.databinding.PopupAddFilterBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.FilterAdapter;
import app.fedilab.android.ui.drawer.KeywordAdapter;
import app.fedilab.android.viewmodel.mastodon.FiltersVM;
public class FilterActivity extends BaseActivity implements FilterAdapter.Delete {
public class FilterActivity extends BaseBarActivity implements FilterAdapter.Delete {
private ActivityFiltersBinding binding;
private List<Filter> filterList;
@ -250,13 +247,12 @@ public class FilterActivity extends BaseActivity implements FilterAdapter.Delete
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivityFiltersBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
filterList = new ArrayList<>();
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
FiltersVM filtersVM = new ViewModelProvider(FilterActivity.this).get(FiltersVM.class);

View file

@ -15,13 +15,11 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -35,7 +33,6 @@ import app.fedilab.android.client.entities.api.Account;
import app.fedilab.android.client.entities.api.Accounts;
import app.fedilab.android.databinding.ActivityStatusInfoBinding;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.AccountFollowRequestAdapter;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
@ -51,14 +48,13 @@ public class FollowRequestActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
binding = ActivityStatusInfoBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
accountList = new ArrayList<>();
flagLoading = false;

View file

@ -15,7 +15,6 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.InputFilter;
import android.view.Menu;
@ -24,7 +23,6 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
@ -46,7 +44,7 @@ import app.fedilab.android.viewmodel.mastodon.TagVM;
import es.dmoral.toasty.Toasty;
public class FollowedTagActivity extends BaseActivity implements FollowedTagAdapter.ActionOnTag {
public class FollowedTagActivity extends BaseBarActivity implements FollowedTagAdapter.ActionOnTag {
private ActivityFollowedTagsBinding binding;
@ -60,14 +58,13 @@ public class FollowedTagActivity extends BaseActivity implements FollowedTagAdap
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivityFollowedTagsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
canGoBack = false;
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
tagVM = new ViewModelProvider(FollowedTagActivity.this).get(TagVM.class);
tagVM.followedTags(BaseMainActivity.currentInstance, BaseMainActivity.currentToken)

View file

@ -18,7 +18,6 @@ package app.fedilab.android.activities;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@ -27,14 +26,15 @@ import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.client.entities.api.Filter;
import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.client.entities.app.Pinned;
import app.fedilab.android.client.entities.app.PinnedTimeline;
@ -44,8 +44,8 @@ import app.fedilab.android.client.entities.app.Timeline;
import app.fedilab.android.databinding.ActivityHashtagBinding;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;
import app.fedilab.android.viewmodel.mastodon.FiltersVM;
import app.fedilab.android.viewmodel.mastodon.ReorderVM;
import app.fedilab.android.viewmodel.mastodon.TagVM;
import es.dmoral.toasty.Toasty;
@ -58,12 +58,14 @@ public class HashTagActivity extends BaseActivity {
private String tag;
private boolean pinnedTag;
private boolean followedTag;
private boolean mutedTag;
private TagVM tagVM;
private Filter fedilabFilter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
ActivityHashtagBinding binding = ActivityHashtagBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
@ -75,12 +77,12 @@ public class HashTagActivity extends BaseActivity {
finish();
pinnedTag = false;
followedTag = false;
mutedTag = false;
setSupportActionBar(binding.toolbar);
ActionBar actionBar = getSupportActionBar();
//Remove title
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
binding.title.setText(tag);
if (getSupportActionBar() != null) {
@ -110,12 +112,31 @@ public class HashTagActivity extends BaseActivity {
}
}
});
if (MainActivity.filterFetched && MainActivity.mainFilters != null) {
for (Filter filter : MainActivity.mainFilters) {
if (filter.title.equalsIgnoreCase(Helper.FEDILAB_MUTED_HASHTAGS)) {
fedilabFilter = filter;
String fetch = tag.startsWith("#") ? tag : "#" + tag;
for (Filter.KeywordsAttributes keywordsAttributes : filter.keywords) {
if (fetch.equalsIgnoreCase(keywordsAttributes.keyword)) {
mutedTag = true;
invalidateOptionsMenu();
break;
}
}
mutedTag = false;
invalidateOptionsMenu();
break;
}
}
} else {
mutedTag = true;
}
Bundle bundle = new Bundle();
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.TAG);
bundle.putString(Helper.ARG_SEARCH_KEYWORD, tag);
Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_tags, new FragmentMastodonTimeline(), bundle, null, null);
binding.toolbar.setPopupTheme(Helper.popupStyle());
binding.compose.setOnClickListener(v -> {
Intent intentToot = new Intent(HashTagActivity.this, ComposeActivity.class);
StatusDraft statusDraft = new StatusDraft();
@ -194,23 +215,70 @@ public class HashTagActivity extends BaseActivity {
invalidateOptionsMenu();
}
});
} else if (item.getItemId() == R.id.action_mute) {
if (MainActivity.mainFilters == null || fedilabFilter == null) {
MainActivity.mainFilters = new ArrayList<>();
Filter.FilterParams filterParams = new Filter.FilterParams();
filterParams.title = Helper.FEDILAB_MUTED_HASHTAGS;
filterParams.filter_action = "hide";
filterParams.context = new ArrayList<>();
filterParams.context.add("home");
filterParams.context.add("public");
filterParams.context.add("thread");
filterParams.context.add("account");
String finalTag = tag;
FiltersVM filtersVM = new ViewModelProvider(HashTagActivity.this).get(FiltersVM.class);
filtersVM.addFilter(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, filterParams)
.observe(HashTagActivity.this, filter -> {
if (filter != null) {
MainActivity.mainFilters.add(filter);
mutedTag = false;
fedilabFilter = filter;
muteTags();
invalidateOptionsMenu();
}
});
} else {
muteTags();
}
}
return super.onOptionsItemSelected(item);
}
private void muteTags() {
Filter.FilterParams filterParams = new Filter.FilterParams();
filterParams.id = fedilabFilter.id;
filterParams.keywords = new ArrayList<>();
Filter.KeywordsParams keywordsParams = new Filter.KeywordsParams();
keywordsParams.whole_word = true;
keywordsParams.keyword = tag.startsWith("#") ? tag : "#" + tag;
filterParams.keywords.add(keywordsParams);
filterParams.context = fedilabFilter.context;
FiltersVM filtersVM = new ViewModelProvider(HashTagActivity.this).get(FiltersVM.class);
filtersVM.editFilter(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, filterParams)
.observe(HashTagActivity.this, filter -> {
mutedTag = true;
invalidateOptionsMenu();
});
}
@Override
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
getMenuInflater().inflate(R.menu.menu_hashtag, menu);
MenuItem pin = menu.findItem(R.id.action_add_timeline);
MenuItem follow = menu.findItem(R.id.action_follow_tag);
MenuItem mute = menu.findItem(R.id.action_mute);
if (pinnedTag && pin != null) {
pin.setVisible(false);
}
if (followedTag && follow != null) {
follow.setVisible(false);
}
mute.setVisible(!mutedTag);
return super.onCreateOptionsMenu(menu);
}

View file

@ -32,7 +32,6 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;
@ -49,7 +48,7 @@ import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.viewmodel.mastodon.InstancesVM;
public class InstanceActivity extends BaseActivity {
public class InstanceActivity extends BaseAlertDialogActivity {
ActivityInstanceBinding binding;
@ -58,7 +57,6 @@ public class InstanceActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeDialog(this);
binding = ActivityInstanceBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
@ -71,13 +69,13 @@ public class InstanceActivity extends BaseActivity {
final SpannableString contentAbout = new SpannableString(getString(R.string.action_about_instance));
contentAbout.setSpan(new UnderlineSpan(), 0, contentAbout.length(), 0);
contentAbout.setSpan(new ForegroundColorSpan(ContextCompat.getColor(InstanceActivity.this, R.color.cyanea_accent_reference)), 0, contentAbout.length(),
contentAbout.setSpan(new ForegroundColorSpan(ThemeHelper.getAttColor(this, R.attr.colorPrimary)), 0, contentAbout.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
binding.tos.setText(contentAbout);
final SpannableString contentPrivacy = new SpannableString(getString(R.string.action_privacy_policy));
contentPrivacy.setSpan(new UnderlineSpan(), 0, contentPrivacy.length(), 0);
contentPrivacy.setSpan(new ForegroundColorSpan(ContextCompat.getColor(InstanceActivity.this, R.color.cyanea_accent_reference)), 0, contentPrivacy.length(),
contentPrivacy.setSpan(new ForegroundColorSpan(ThemeHelper.getAttColor(this, R.attr.colorPrimary)), 0, contentPrivacy.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
binding.privacy.setText(contentPrivacy);

View file

@ -24,7 +24,6 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import com.bumptech.glide.Glide;
@ -38,14 +37,13 @@ import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.viewmodel.mastodon.InstanceSocialVM;
public class InstanceHealthActivity extends BaseActivity {
public class InstanceHealthActivity extends BaseAlertDialogActivity {
private ActivityInstanceSocialBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeDialog(this);
binding = ActivityInstanceSocialBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
@ -91,10 +89,10 @@ public class InstanceHealthActivity extends BaseActivity {
binding.name.setText(instanceSocial.name);
if (instanceSocial.up) {
binding.up.setText(R.string.is_up);
binding.up.setTextColor(ContextCompat.getColor(InstanceHealthActivity.this, R.color.green_1));
binding.up.setTextColor(ThemeHelper.getAttColor(this, R.attr.colorPrimary));
} else {
binding.up.setText(R.string.is_down);
binding.up.setTextColor(ContextCompat.getColor(InstanceHealthActivity.this, R.color.red_1));
binding.up.setTextColor(ThemeHelper.getAttColor(this, R.attr.colorError));
}
binding.uptime.setText(getString(R.string.instance_health_uptime, (instanceSocial.uptime * 100)));
if (instanceSocial.checked_at != null)

View file

@ -28,11 +28,10 @@ import androidx.lifecycle.ViewModelProvider;
import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityInstanceProfileBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.viewmodel.mastodon.NodeInfoVM;
import es.dmoral.toasty.Toasty;
public class InstanceProfileActivity extends BaseActivity {
public class InstanceProfileActivity extends BaseAlertDialogActivity {
private String instance;
@ -41,7 +40,7 @@ public class InstanceProfileActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeDialog(this);
binding = ActivityInstanceProfileBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

View file

@ -15,11 +15,16 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.helper.Helper.PREF_USER_TOKEN;
import static app.fedilab.android.helper.MastodonHelper.REDIRECT_CONTENT_WEB;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.FrameLayout;
@ -32,10 +37,11 @@ import org.jetbrains.annotations.NotNull;
import java.util.regex.Matcher;
import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.client.entities.app.Account;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.fragment.login.FragmentLoginMain;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
import app.fedilab.android.viewmodel.mastodon.AdminVM;
@ -49,7 +55,34 @@ public class LoginActivity extends BaseActivity {
public static Account.API apiLogin;
public static String currentInstanceLogin, client_idLogin, client_secretLogin, softwareLogin;
private final int PICK_IMPORT = 5557;
private boolean requestedAdmin;
public static boolean requestedAdmin;
@SuppressLint("ApplySharedPref")
public static void proceedLogin(Activity activity, Account account) {
new Thread(() -> {
try {
//update the database
new Account(activity).insertOrUpdate(account);
Handler mainHandler = new Handler(Looper.getMainLooper());
BaseMainActivity.currentToken = account.token;
BaseMainActivity.currentUserID = account.user_id;
BaseMainActivity.api = Account.API.MASTODON;
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(PREF_USER_TOKEN, account.token);
editor.commit();
//The user is now authenticated, it will be redirected to MainActivity
Runnable myRunnable = () -> {
Intent mainActivity = new Intent(activity, MainActivity.class);
activity.startActivity(mainActivity);
activity.finish();
};
mainHandler.post(myRunnable);
} catch (DBException e) {
e.printStackTrace();
}
}).start();
}
private void manageItent(Intent intent) {
@ -85,10 +118,10 @@ public class LoginActivity extends BaseActivity {
AdminVM adminVM = new ViewModelProvider(LoginActivity.this).get(AdminVM.class);
adminVM.getAccount(account.instance, account.token, account.user_id).observe(LoginActivity.this, adminAccount -> {
account.admin = adminAccount != null;
WebviewConnectActivity.proceedLogin(LoginActivity.this, account);
proceedLogin(LoginActivity.this, account);
});
} else {
WebviewConnectActivity.proceedLogin(LoginActivity.this, account);
proceedLogin(LoginActivity.this, account);
}
});
} else {
@ -99,7 +132,6 @@ public class LoginActivity extends BaseActivity {
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
@ -109,24 +141,16 @@ public class LoginActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
setContentView(new FrameLayout(this));
FragmentLoginMain fragmentLoginMain = new FragmentLoginMain();
Helper.addFragment(getSupportFragmentManager(), android.R.id.content, fragmentLoginMain, null, null, null);
requestedAdmin = false;
//The activity handles a redirect URI, it will extract token code and will proceed to authentication
//That happens when the user wants to use an external browser
manageItent(getIntent());
}
public boolean requestedAdmin() {
return requestedAdmin;
}
public boolean setAdmin(boolean askAdmin) {
return requestedAdmin = askAdmin;
}
@Override
protected void onResume() {
@ -138,9 +162,6 @@ public class LoginActivity extends BaseActivity {
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_login, menu);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
boolean embedded_browser = sharedpreferences.getBoolean(getString(R.string.SET_EMBEDDED_BROWSER), true);
menu.findItem(R.id.action_custom_tabs).setChecked(!embedded_browser);
return true;
}
@ -154,13 +175,6 @@ public class LoginActivity extends BaseActivity {
if (id == R.id.action_proxy) {
Intent intent = new Intent(LoginActivity.this, ProxyActivity.class);
startActivity(intent);
} else if (id == R.id.action_custom_tabs) {
item.setChecked(!item.isChecked());
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(getString(R.string.SET_EMBEDDED_BROWSER), !item.isChecked());
editor.apply();
return false;
} else if (id == R.id.action_request_admin) {
item.setChecked(!item.isChecked());
requestedAdmin = item.isChecked();

View file

@ -16,7 +16,6 @@ package app.fedilab.android.activities;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
@ -28,7 +27,6 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
@ -62,7 +60,7 @@ import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
import es.dmoral.toasty.Toasty;
public class MastodonListActivity extends BaseActivity implements MastodonListAdapter.ActionOnList {
public class MastodonListActivity extends BaseBarActivity implements MastodonListAdapter.ActionOnList {
AccountListAdapter accountsInListAdapter;
@ -82,14 +80,13 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivityListBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
canGoBack = false;
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
flagLoading = false;
orderASC = true;

View file

@ -24,7 +24,6 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -64,13 +63,12 @@ import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.databinding.ActivityMediaPagerBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MediaHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.interfaces.OnDownloadInterface;
import app.fedilab.android.ui.fragment.media.FragmentMedia;
import es.dmoral.toasty.Toasty;
public class MediaActivity extends BaseActivity implements OnDownloadInterface {
public class MediaActivity extends BaseTransparentActivity implements OnDownloadInterface {
int flags;
private ArrayList<Attachment> attachments;
@ -114,7 +112,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ThemeHelper.applyThemeBar(this);
super.onCreate(savedInstanceState);
ActivityCompat.postponeEnterTransition(MediaActivity.this);
binding = ActivityMediaPagerBinding.inflate(getLayoutInflater());
@ -132,7 +130,6 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
if (attachments == null || attachments.size() == 0)
@ -400,7 +397,11 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
}
} else {
binding.translate.setVisibility(View.GONE);
binding.originalMessage.setVisibility(View.INVISIBLE);
if (status != null) {
binding.originalMessage.setVisibility(View.VISIBLE);
} else {
binding.originalMessage.setVisibility(View.INVISIBLE);
}
binding.mediaDescriptionTranslated.setVisibility(View.GONE);
binding.mediaDescription.setVisibility(View.GONE);
}

View file

@ -16,7 +16,6 @@ package app.fedilab.android.activities;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
@ -25,7 +24,6 @@ import android.view.View;
import android.widget.TextView;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import java.util.ArrayList;
@ -39,23 +37,21 @@ import app.fedilab.android.databinding.ActivityPartnershipBinding;
import app.fedilab.android.helper.CrossActionHelper;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
public class PartnerShipActivity extends BaseActivity {
public class PartnerShipActivity extends BaseBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
ActivityPartnershipBinding binding = ActivityPartnershipBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
TextView about_partnership = findViewById(R.id.about_partnership);
@ -65,9 +61,8 @@ public class PartnerShipActivity extends BaseActivity {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://masto.host"));
startActivity(browserIntent);
});
binding.accountFollow.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(PartnerShipActivity.this));
setTitle(R.string.action_partnership);
binding.accountFollow.setImageResource(R.drawable.ic_baseline_person_add_24);
binding.accountFollow.setIconResource(R.drawable.ic_baseline_person_add_24);
CrossActionHelper.fetchRemoteAccount(PartnerShipActivity.this, "@mastohost@mastodon.social", new CrossActionHelper.Callback() {
@Override
public void federatedStatus(Status status) {

View file

@ -25,7 +25,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableString;
@ -48,6 +47,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
@ -135,7 +135,7 @@ public class ProfileActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
binding = ActivityProfileBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
@ -149,12 +149,10 @@ public class ProfileActivity extends BaseActivity {
mention_str = b.getString(Helper.ARG_MENTION, null);
checkRemotely = b.getBoolean(Helper.ARG_CHECK_REMOTELY, false);
}
postponeEnterTransition();
ActivityCompat.postponeEnterTransition(ProfileActivity.this);
//Remove title
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
if (getSupportActionBar() != null) {
@ -164,7 +162,6 @@ public class ProfileActivity extends BaseActivity {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
binding.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
binding.toolbar.setPopupTheme(Helper.popupStyle());
accountsVM = new ViewModelProvider(ProfileActivity.this).get(AccountsVM.class);
if (account != null) {
initializeView(account);
@ -263,8 +260,6 @@ public class ProfileActivity extends BaseActivity {
public void onTabReselected(TabLayout.Tab tab) {
}
});
binding.accountTabLayout.setTabTextColors(ThemeHelper.getAttColor(ProfileActivity.this, R.attr.mTextColor), ContextCompat.getColor(ProfileActivity.this, R.color.cyanea_accent_dark_reference));
binding.accountTabLayout.setTabIconTint(ThemeHelper.getColorStateList(ProfileActivity.this));
boolean disableGif = sharedpreferences.getBoolean(getString(R.string.SET_DISABLE_GIF), false);
String targetedUrl = disableGif ? account.avatar_static : account.avatar;
Glide.with(ProfileActivity.this)
@ -275,23 +270,27 @@ public class ProfileActivity extends BaseActivity {
@Override
public void onResourceReady(@NonNull final Drawable resource, Transition<? super Drawable> transition) {
binding.profilePicture.setImageDrawable(resource);
startPostponedEnterTransition();
binding.accountPp.setImageDrawable(resource);
ActivityCompat.startPostponedEnterTransition(ProfileActivity.this);
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
binding.profilePicture.setImageResource(R.drawable.ic_person);
startPostponedEnterTransition();
binding.accountPp.setImageResource(R.drawable.ic_person);
ActivityCompat.startPostponedEnterTransition(ProfileActivity.this);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
binding.profilePicture.setImageResource(R.drawable.ic_person);
binding.accountPp.setImageResource(R.drawable.ic_person);
ActivityCompat.startPostponedEnterTransition(ProfileActivity.this);
}
}
);
//Load header
MastodonHelper.loadProfileMediaMastodon(binding.bannerPp, account, MastodonHelper.MediaAccountType.HEADER);
MastodonHelper.loadProfileMediaMastodon(ProfileActivity.this, binding.bannerPp, account, MastodonHelper.MediaAccountType.HEADER);
//Redraws icon for locked accounts
final float scale = getResources().getDisplayMetrics().density;
if (account.locked) {
@ -314,7 +313,7 @@ public class ProfileActivity extends BaseActivity {
final SpannableString content = new SpannableString(getString(R.string.disclaimer_full));
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
content.setSpan(new ForegroundColorSpan(ContextCompat.getColor(ProfileActivity.this, R.color.cyanea_accent_reference)), 0, content.length(),
content.setSpan(new ForegroundColorSpan(ThemeHelper.getAttColor(this, R.attr.colorPrimary)), 0, content.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
binding.warningMessage.setText(content);
binding.warningMessage.setOnClickListener(view -> {
@ -346,7 +345,6 @@ public class ProfileActivity extends BaseActivity {
else
binding.warningContainer.setVisibility(View.GONE);
binding.openRemoteProfile.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(ProfileActivity.this));
if (checkRemotely) {
binding.openRemoteProfile.setVisibility(View.GONE);
}
@ -392,7 +390,7 @@ public class ProfileActivity extends BaseActivity {
TextView.BufferType.SPANNABLE);
binding.accountNote.setMovementMethod(LinkMovementMethod.getInstance());
MastodonHelper.loadPPMastodon(binding.accountPp, account);
//MastodonHelper.loadPPMastodon(binding.accountPp, account);
binding.accountPp.setOnClickListener(v -> {
Intent intent = new Intent(ProfileActivity.this, MediaActivity.class);
Bundle b = new Bundle();
@ -526,13 +524,12 @@ public class ProfileActivity extends BaseActivity {
});
}
}
binding.accountFollow.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(ProfileActivity.this));
binding.accountFollow.setEnabled(true);
//Visibility depending of the relationship
if (relationship != null) {
if (relationship.blocked_by) {
binding.accountFollow.setImageResource(R.drawable.ic_baseline_person_add_24);
binding.accountFollow.setIconResource(R.drawable.ic_baseline_person_add_24);
binding.accountFollow.setVisibility(View.VISIBLE);
binding.accountFollow.setEnabled(false);
binding.accountFollow.setContentDescription(getString(R.string.action_disabled));
@ -540,7 +537,7 @@ public class ProfileActivity extends BaseActivity {
if (relationship.requested) {
binding.accountFollowRequest.setVisibility(View.VISIBLE);
binding.accountFollow.setImageResource(R.drawable.ic_baseline_hourglass_full_24);
binding.accountFollow.setIconResource(R.drawable.ic_baseline_hourglass_full_24);
binding.accountFollow.setVisibility(View.VISIBLE);
binding.accountFollow.setContentDescription(getString(R.string.follow_request));
doAction = action.UNFOLLOW;
@ -551,19 +548,19 @@ public class ProfileActivity extends BaseActivity {
binding.accountFollowedBy.setVisibility(View.GONE);
}
if (relationship.following) {
binding.accountFollow.setImageResource(R.drawable.ic_baseline_person_remove_24);
binding.accountFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(ProfileActivity.this, R.color.red_1)));
binding.accountFollow.setIconResource(R.drawable.ic_baseline_person_remove_24);
binding.accountFollow.setBackgroundTintList(ColorStateList.valueOf(ThemeHelper.getAttColor(this, R.attr.colorError)));
doAction = action.UNFOLLOW;
binding.accountFollow.setContentDescription(getString(R.string.action_unfollow));
binding.accountFollow.setVisibility(View.VISIBLE);
} else if (relationship.blocking) {
binding.accountFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(ProfileActivity.this, R.color.red_1)));
binding.accountFollow.setImageResource(R.drawable.ic_baseline_lock_open_24);
binding.accountFollow.setBackgroundTintList(ColorStateList.valueOf(ThemeHelper.getAttColor(this, R.attr.colorError)));
binding.accountFollow.setIconResource(R.drawable.ic_baseline_lock_open_24);
doAction = action.UNBLOCK;
binding.accountFollow.setVisibility(View.VISIBLE);
binding.accountFollow.setContentDescription(getString(R.string.action_unblock));
} else {
binding.accountFollow.setImageResource(R.drawable.ic_baseline_person_add_24);
binding.accountFollow.setIconResource(R.drawable.ic_baseline_person_add_24);
doAction = action.FOLLOW;
binding.accountFollow.setVisibility(View.VISIBLE);
binding.accountFollow.setContentDescription(getString(R.string.action_follow));
@ -575,16 +572,15 @@ public class ProfileActivity extends BaseActivity {
binding.headerEditProfile.setVisibility(View.VISIBLE);
binding.headerEditProfile.bringToFront();
}
binding.headerEditProfile.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(ProfileActivity.this));
if (!relationship.following) {
binding.accountNotification.setVisibility(View.GONE);
} else {
binding.accountNotification.setVisibility(View.VISIBLE);
}
if (relationship.notifying) {
binding.accountNotification.setImageResource(R.drawable.ic_baseline_notifications_active_24);
binding.accountNotification.setIconResource(R.drawable.ic_baseline_notifications_active_24);
} else {
binding.accountNotification.setImageResource(R.drawable.ic_baseline_notifications_off_24);
binding.accountNotification.setIconResource(R.drawable.ic_baseline_notifications_off_24);
}
binding.accountNotification.setOnClickListener(v -> {
if (relationship != null && relationship.following) {

View file

@ -29,7 +29,7 @@ import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityProxyBinding;
public class ProxyActivity extends BaseActivity {
public class ProxyActivity extends BaseAlertDialogActivity {
private ActivityProxyBinding binding;
private int position;

View file

@ -20,7 +20,6 @@ import static app.fedilab.android.helper.PinnedTimelineHelper.sortPositionAsc;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
@ -34,7 +33,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
@ -57,7 +55,6 @@ import app.fedilab.android.databinding.ActivityReorderTabsBinding;
import app.fedilab.android.databinding.PopupSearchInstanceBinding;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.helper.itemtouchhelper.OnStartDragListener;
import app.fedilab.android.helper.itemtouchhelper.SimpleItemTouchHelperCallback;
import app.fedilab.android.ui.drawer.ReorderBottomMenuAdapter;
@ -74,7 +71,7 @@ import okhttp3.RequestBody;
import okhttp3.Response;
public class ReorderTimelinesActivity extends BaseActivity implements OnStartDragListener {
public class ReorderTimelinesActivity extends BaseBarActivity implements OnStartDragListener {
private ItemTouchHelper touchHelper;
@ -100,13 +97,12 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivityReorderTabsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
searchInstanceRunning = false;
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ReorderTimelinesActivity.this);

View file

@ -14,7 +14,6 @@ package app.fedilab.android.activities;
* 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.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
@ -22,7 +21,6 @@ import android.widget.RadioButton;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
@ -39,14 +37,13 @@ import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.client.entities.app.Timeline;
import app.fedilab.android.databinding.ActivityReportBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.RulesAdapter;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
import es.dmoral.toasty.Toasty;
public class ReportActivity extends BaseActivity {
public class ReportActivity extends BaseBarActivity {
private ActivityReportBinding binding;
private Status status;
@ -64,14 +61,13 @@ public class ReportActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivityReportBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
Bundle b = getIntent().getExtras();

View file

@ -17,14 +17,12 @@ package app.fedilab.android.activities;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.MenuItem;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import com.google.android.material.tabs.TabLayout;
@ -32,7 +30,6 @@ import com.google.android.material.tabs.TabLayout;
import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityScheduledBinding;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.pageadapter.FedilabScheduledPageAdapter;
public class ScheduledActivity extends BaseActivity {
@ -42,7 +39,7 @@ public class ScheduledActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
binding = ActivityScheduledBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
@ -50,7 +47,6 @@ public class ScheduledActivity extends BaseActivity {
//Remove title
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -68,8 +64,7 @@ public class ScheduledActivity extends BaseActivity {
binding.scheduleViewpager.setAdapter(new FedilabScheduledPageAdapter(getSupportFragmentManager()));
binding.scheduleViewpager.setOffscreenPageLimit(3);
binding.scheduleViewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.scheduleTablayout));
binding.scheduleTablayout.setTabTextColors(ThemeHelper.getAttColor(ScheduledActivity.this, R.attr.mTextColor), ContextCompat.getColor(ScheduledActivity.this, R.color.cyanea_accent_dark_reference));
binding.scheduleTablayout.setTabIconTint(ThemeHelper.getColorStateList(ScheduledActivity.this));
binding.scheduleTablayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override

View file

@ -16,7 +16,6 @@ package app.fedilab.android.activities;
import android.app.SearchManager;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
@ -27,7 +26,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.SearchView;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
@ -41,14 +39,13 @@ import org.jetbrains.annotations.NotNull;
import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivitySearchResultTabsBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonAccount;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTag;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;
import es.dmoral.toasty.Toasty;
public class SearchResultTabActivity extends BaseActivity {
public class SearchResultTabActivity extends BaseBarActivity {
private String search;
@ -58,7 +55,7 @@ public class SearchResultTabActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivitySearchResultTabsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
@ -75,7 +72,6 @@ public class SearchResultTabActivity extends BaseActivity {
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
setTitle(search);
initial = binding.searchTabLayout.newTab();
@ -83,8 +79,6 @@ public class SearchResultTabActivity extends BaseActivity {
binding.searchTabLayout.addTab(binding.searchTabLayout.newTab().setText(getString(R.string.accounts)));
binding.searchTabLayout.addTab(binding.searchTabLayout.newTab().setText(getString(R.string.toots)));
binding.searchTabLayout.addTab(binding.searchTabLayout.newTab().setText(getString(R.string.action_cache)));
binding.searchTabLayout.setTabTextColors(ThemeHelper.getAttColor(SearchResultTabActivity.this, R.attr.mTextColor), ContextCompat.getColor(SearchResultTabActivity.this, R.color.cyanea_accent_dark_reference));
binding.searchTabLayout.setTabIconTint(ThemeHelper.getColorStateList(SearchResultTabActivity.this));
binding.searchTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {

View file

@ -16,24 +16,20 @@ package app.fedilab.android.activities
import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AlertDialog
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import app.fedilab.android.R
import app.fedilab.android.databinding.ActivitySettingsBinding
import app.fedilab.android.helper.Helper
import app.fedilab.android.helper.ThemeHelper
import app.fedilab.android.ui.fragment.settings.FragmentThemingSettings
class SettingsActivity : BaseActivity(), FragmentThemingSettings.ActionTheming {
class SettingsActivity : BaseBarActivity() {
private lateinit var binding: ActivitySettingsBinding
private lateinit var appBarConfiguration: AppBarConfiguration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ThemeHelper.applyThemeBar(this)
binding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(binding.root)
@ -56,15 +52,4 @@ class SettingsActivity : BaseActivity(), FragmentThemingSettings.ActionTheming {
return super.onOptionsItemSelected(item)
}
override fun restart() {
val restartBuilder = AlertDialog.Builder(this, Helper.dialogStyle())
restartBuilder.setTitle(getString(R.string.restart_the_app))
restartBuilder.setMessage(getString(R.string.restart_the_app_theme))
restartBuilder.setNegativeButton(R.string.no) { dialog, which -> dialog.dismiss() }
restartBuilder.setPositiveButton(R.string.restart) { dialog, which ->
dialog.dismiss()
Helper.restart(this)
}
restartBuilder.create().show()
}
}

View file

@ -16,38 +16,34 @@ package app.fedilab.android.activities;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityStatusHistoryBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.StatusHistoryAdapter;
import app.fedilab.android.viewmodel.mastodon.StatusesVM;
import es.dmoral.toasty.Toasty;
public class StatusHistoryActivity extends BaseActivity {
public class StatusHistoryActivity extends BaseBarActivity {
public static Resources.Theme theme;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
ActivityStatusHistoryBinding binding = ActivityStatusHistoryBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
Bundle b = getIntent().getExtras();

View file

@ -15,13 +15,11 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -37,7 +35,6 @@ import app.fedilab.android.client.entities.api.RelationShip;
import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.databinding.ActivityStatusInfoBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.AccountAdapter;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
import app.fedilab.android.viewmodel.mastodon.StatusesVM;
@ -56,14 +53,13 @@ public class StatusInfoActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
binding = ActivityStatusInfoBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
accountList = new ArrayList<>();
Bundle b = getIntent().getExtras();

View file

@ -14,35 +14,30 @@ package app.fedilab.android.activities;
* 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.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.core.content.ContextCompat;
import org.jetbrains.annotations.NotNull;
import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivitySuggestionsBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonSuggestion;
public class SuggestionActivity extends BaseActivity {
public class SuggestionActivity extends BaseBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
ActivitySuggestionsBinding binding = ActivitySuggestionsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_suggestions, new FragmentMastodonSuggestion(), null, null, null);

View file

@ -14,13 +14,11 @@ package app.fedilab.android.activities;
* 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.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
@ -35,12 +33,11 @@ import app.fedilab.android.R;
import app.fedilab.android.client.entities.app.Timeline;
import app.fedilab.android.databinding.ActivityTrendsBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTag;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;
public class TrendsActivity extends BaseActivity {
public class TrendsActivity extends BaseBarActivity {
private ActivityTrendsBinding binding;
@ -48,20 +45,17 @@ public class TrendsActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivityTrendsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
binding.searchTabLayout.addTab(binding.searchTabLayout.newTab().setText(getString(R.string.tags)));
binding.searchTabLayout.addTab(binding.searchTabLayout.newTab().setText(getString(R.string.toots)));
binding.searchTabLayout.setTabTextColors(ThemeHelper.getAttColor(TrendsActivity.this, R.attr.mTextColor), ContextCompat.getColor(TrendsActivity.this, R.color.cyanea_accent_dark_reference));
binding.searchTabLayout.setTabIconTint(ThemeHelper.getColorStateList(TrendsActivity.this));
binding.searchTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {

View file

@ -1,255 +0,0 @@
package app.fedilab.android.activities;
/* Copyright 2021 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.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityWebviewBinding;
import app.fedilab.android.helper.CountDrawable;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.webview.CustomWebview;
import app.fedilab.android.webview.FedilabWebChromeClient;
import app.fedilab.android.webview.FedilabWebViewClient;
import es.dmoral.toasty.Toasty;
public class WebviewActivity extends BaseActivity {
private String url;
private boolean peertubeLink;
private CustomWebview webView;
private FedilabWebViewClient FedilabWebViewClient;
private ActivityWebviewBinding binding;
private Menu defaultMenu;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
binding = ActivityWebviewBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
setSupportActionBar(binding.toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
}
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
Bundle b = getIntent().getExtras();
if (b != null) {
url = b.getString("url", null);
peertubeLink = b.getBoolean("peertubeLink", false);
}
if (url == null)
finish();
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
webView = Helper.initializeWebview(WebviewActivity.this, R.id.webview, null);
setTitle("");
webView.getSettings().setJavaScriptEnabled(true);
FedilabWebChromeClient FedilabWebChromeClient = new FedilabWebChromeClient(WebviewActivity.this, webView, binding.webviewContainer, binding.videoLayout);
FedilabWebChromeClient.setOnToggledFullscreen(fullscreen -> {
if (fullscreen) {
binding.videoLayout.setVisibility(View.VISIBLE);
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(attrs);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
} else {
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(attrs);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
binding.videoLayout.setVisibility(View.GONE);
}
});
webView.setWebChromeClient(FedilabWebChromeClient);
FedilabWebViewClient = new FedilabWebViewClient(WebviewActivity.this);
webView.setWebViewClient(FedilabWebViewClient);
webView.setDownloadListener((url, userAgent, contentDisposition, mimetype, contentLength) -> {
if (Build.VERSION.SDK_INT >= 23) {
if (ContextCompat.checkSelfPermission(WebviewActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(WebviewActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(WebviewActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
} else {
Helper.manageDownloads(WebviewActivity.this, url);
}
} else {
Helper.manageDownloads(WebviewActivity.this, url);
}
});
if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://"))
url = "http://" + url;
webView.loadUrl(url);
}
public void setCount(Context context, String count) {
if (defaultMenu != null && !peertubeLink) {
MenuItem menuItem = defaultMenu.findItem(R.id.action_block);
LayerDrawable icon = (LayerDrawable) menuItem.getIcon();
CountDrawable badge;
// Reuse drawable if possible
Drawable reuse = icon.findDrawableByLayerId(R.id.ic_block_count);
if (reuse instanceof CountDrawable) {
badge = (CountDrawable) reuse;
} else {
badge = new CountDrawable(context);
}
badge.setCount(count);
icon.mutate();
icon.setDrawableByLayerId(R.id.ic_block_count, badge);
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (!peertubeLink)
setCount(WebviewActivity.this, "0");
defaultMenu = menu;
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
getMenuInflater().inflate(R.menu.main_webview, menu);
defaultMenu = menu;
if (peertubeLink) {
menu.findItem(R.id.action_go).setVisible(false);
menu.findItem(R.id.action_block).setVisible(false);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId == android.R.id.home) {
finish();
return true;
} else if (itemId == R.id.action_block) {
List<String> domains = FedilabWebViewClient.getDomains();
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(WebviewActivity.this, R.layout.domains_blocked);
arrayAdapter.addAll(domains);
AlertDialog.Builder builder = new AlertDialog.Builder(WebviewActivity.this, Helper.dialogStyle());
builder.setTitle(R.string.list_of_blocked_domains);
builder.setNegativeButton(R.string.close, (dialog, which) -> dialog.dismiss());
builder.setAdapter(arrayAdapter, (dialog, which) -> {
String strName = arrayAdapter.getItem(which);
assert strName != null;
Toasty.info(WebviewActivity.this, strName, Toast.LENGTH_LONG).show();
});
builder.show();
return true;
} else if (itemId == R.id.action_go) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
try {
startActivity(browserIntent);
} catch (Exception e) {
Toasty.error(WebviewActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
return true;
}
return super.onOptionsItemSelected(item);
}
public void setUrl(String newUrl) {
this.url = newUrl;
}
@Override
public void onPause() {
super.onPause();
if (webView != null)
webView.onPause();
}
@Override
public void onResume() {
super.onResume();
if (webView != null)
webView.onResume();
}
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (webView != null)
webView.destroy();
}
}

View file

@ -1,326 +0,0 @@
/* Copyright 2021 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 static app.fedilab.android.activities.LoginActivity.apiLogin;
import static app.fedilab.android.activities.LoginActivity.client_idLogin;
import static app.fedilab.android.activities.LoginActivity.client_secretLogin;
import static app.fedilab.android.activities.LoginActivity.currentInstanceLogin;
import static app.fedilab.android.activities.LoginActivity.softwareLogin;
import static app.fedilab.android.helper.Helper.PREF_USER_TOKEN;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import androidx.appcompat.app.AlertDialog;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Matcher;
import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.client.entities.app.Account;
import app.fedilab.android.databinding.ActivityWebviewConnectBinding;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
import app.fedilab.android.viewmodel.mastodon.AdminVM;
import app.fedilab.android.viewmodel.mastodon.OauthVM;
import es.dmoral.toasty.Toasty;
public class WebviewConnectActivity extends BaseActivity {
private ActivityWebviewConnectBinding binding;
private AlertDialog alert;
private String login_url;
private boolean requestedAdmin;
@SuppressWarnings("deprecation")
public static void clearCookies(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
CookieManager.getInstance().removeAllCookies(null);
CookieManager.getInstance().flush();
} else {
CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
cookieSyncMngr.startSync();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
cookieManager.removeSessionCookie();
cookieSyncMngr.stopSync();
cookieSyncMngr.sync();
}
}
@SuppressLint("ApplySharedPref")
public static void proceedLogin(Activity activity, Account account) {
new Thread(() -> {
try {
//update the database
new Account(activity).insertOrUpdate(account);
Handler mainHandler = new Handler(Looper.getMainLooper());
BaseMainActivity.currentToken = account.token;
BaseMainActivity.currentUserID = account.user_id;
BaseMainActivity.api = Account.API.MASTODON;
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(PREF_USER_TOKEN, account.token);
editor.commit();
//The user is now authenticated, it will be redirected to MainActivity
Runnable myRunnable = () -> {
Intent mainActivity = new Intent(activity, MainActivity.class);
activity.startActivity(mainActivity);
activity.finish();
};
mainHandler.post(myRunnable);
} catch (DBException e) {
e.printStackTrace();
}
}).start();
}
@SuppressLint("SetJavaScriptEnabled")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(WebviewConnectActivity.this);
binding = ActivityWebviewConnectBinding.inflate(getLayoutInflater());
View rootView = binding.getRoot();
setContentView(rootView);
Bundle b = getIntent().getExtras();
if (b != null) {
login_url = b.getString("login_url");
requestedAdmin = b.getBoolean("requestedAdmin", false);
}
if (login_url == null)
finish();
clearCookies(WebviewConnectActivity.this);
binding.webviewConnect.getSettings().setJavaScriptEnabled(true);
String user_agent = sharedpreferences.getString(getString(R.string.SET_CUSTOM_USER_AGENT), Helper.USER_AGENT);
binding.webviewConnect.getSettings().setUserAgentString(user_agent);
binding.webviewConnect.getSettings().setDomStorageEnabled(true);
CookieManager.getInstance().setAcceptThirdPartyCookies(binding.webviewConnect, true);
final ProgressBar pbar = findViewById(R.id.progress_bar);
binding.webviewConnect.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
if (progress < 100 && pbar.getVisibility() == ProgressBar.GONE) {
pbar.setVisibility(ProgressBar.VISIBLE);
}
pbar.setProgress(progress);
if (progress == 100) {
pbar.setVisibility(ProgressBar.GONE);
}
}
});
binding.webviewConnect.setWebViewClient(new WebViewClient() {
/* @Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
String x_xsrf_token = null;
String x_csrf_token = null;
if (request.getUrl().toString().contains("accounts/verify_credentials")) {
String cookies = CookieManager.getInstance().getCookie(request.getUrl().toString());
Map<String, String> requestHeaders = request.getRequestHeaders();
Iterator<Map.Entry<String, String>> it = requestHeaders.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pair = it.next();
if (pair.getKey().compareTo("X-XSRF-TOKEN") == 0) {
x_xsrf_token = pair.getValue();
}
if (pair.getKey().compareTo("X-CSRF-TOKEN") == 0) {
x_csrf_token = pair.getValue();
}
it.remove();
}
if (x_xsrf_token != null && x_csrf_token != null) {
String finalX_xsrf_token = x_xsrf_token;
String finalX_csrf_token = x_csrf_token;
new Handler(Looper.getMainLooper()).post(() -> {
view.stopLoading();
SharedPreferences sharedpreferences1 = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences1.edit();
String token = "X-XSRF-TOKEN= " + finalX_xsrf_token + ";X-CSRF-TOKEN= " + finalX_csrf_token + "|" + cookies;
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
editor.commit();
view.setVisibility(View.GONE);
//Update the account with the token;
new UpdateAccountInfoAsyncTask(WebviewConnectActivity.this, token, clientId, clientSecret, null, instance, social);
});
}
}
return super.shouldInterceptRequest(view, request);
}*/
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
if (request.getUrl().toString().contains(currentInstanceLogin + "/api/v1")) {
request.getRequestHeaders();
Map<String, String> requestHeaders = request.getRequestHeaders();
Iterator<Map.Entry<String, String>> it = requestHeaders.entrySet().iterator();
String token = null;
while (it.hasNext()) {
Map.Entry<String, String> pair = it.next();
if (pair.getKey().equals("Authorization")) {
token = pair.getValue();
break;
}
it.remove();
}
if (token != null) {
AccountsVM accountsVM = new ViewModelProvider(WebviewConnectActivity.this).get(AccountsVM.class);
String finalToken = token;
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
accountsVM.getConnectedAccount(currentInstanceLogin, finalToken).observe(WebviewConnectActivity.this, mastodonAccount -> {
if (mastodonAccount != null) {
Account account = new Account();
account.client_id = client_idLogin;
account.client_secret = client_secretLogin;
account.token = finalToken;
account.api = apiLogin;
account.software = softwareLogin;
account.instance = currentInstanceLogin;
account.mastodon_account = mastodonAccount;
account.user_id = mastodonAccount.id;
//We check if user have really moderator rights
if (requestedAdmin) {
AdminVM adminVM = new ViewModelProvider(WebviewConnectActivity.this).get(AdminVM.class);
adminVM.getAccount(account.instance, account.token, account.user_id).observe(WebviewConnectActivity.this, adminAccount -> {
account.admin = adminAccount != null;
proceedLogin(WebviewConnectActivity.this, account);
});
} else {
proceedLogin(WebviewConnectActivity.this, account);
}
} else {
Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
}
});
};
mainHandler.post(myRunnable);
}
}
return super.shouldInterceptRequest(view, request);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
super.shouldOverrideUrlLoading(view, url);
if (url.contains(Helper.REDIRECT_CONTENT_WEB)) {
Matcher matcher = Helper.codePattern.matcher(url);
if (!matcher.find()) {
return false;
}
String code = matcher.group(1);
OauthVM oauthVM = new ViewModelProvider(WebviewConnectActivity.this).get(OauthVM.class);
//API call to get the user token
String scope = requestedAdmin ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES;
oauthVM.createToken(currentInstanceLogin, "authorization_code", client_idLogin, client_secretLogin, Helper.REDIRECT_CONTENT_WEB, scope, code)
.observe(WebviewConnectActivity.this, tokenObj -> {
if (tokenObj != null) {
Account account = new Account();
account.client_id = client_idLogin;
account.client_secret = client_secretLogin;
account.token = tokenObj.token_type + " " + tokenObj.access_token;
account.api = apiLogin;
account.software = softwareLogin;
account.instance = currentInstanceLogin;
//API call to retrieve account information for the new token
AccountsVM accountsVM = new ViewModelProvider(WebviewConnectActivity.this).get(AccountsVM.class);
accountsVM.getConnectedAccount(currentInstanceLogin, account.token).observe(WebviewConnectActivity.this, mastodonAccount -> {
if (mastodonAccount != null) {
account.mastodon_account = mastodonAccount;
account.user_id = mastodonAccount.id;
//We check if user have really moderator rights
if (requestedAdmin) {
AdminVM adminVM = new ViewModelProvider(WebviewConnectActivity.this).get(AdminVM.class);
adminVM.getAccount(account.instance, account.token, account.user_id).observe(WebviewConnectActivity.this, adminAccount -> {
account.admin = adminAccount != null;
proceedLogin(WebviewConnectActivity.this, account);
});
} else {
proceedLogin(WebviewConnectActivity.this, account);
}
} else {
Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
}
});
} else {
Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_token), Toasty.LENGTH_SHORT).show();
}
});
return true;
} else {
return false;
}
}
});
binding.webviewConnect.loadUrl(login_url);
}
@Override
public void onBackPressed() {
if (binding.webviewConnect.canGoBack()) {
binding.webviewConnect.goBack();
} else {
super.onBackPressed();
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (alert != null) {
alert.dismiss();
alert = null;
}
binding.webviewConnect.destroy();
}
}

View file

@ -19,7 +19,6 @@ import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableString;
@ -83,7 +82,7 @@ public class AdminAccountActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
binding = ActivityAdminAccountBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
@ -99,7 +98,6 @@ public class AdminAccountActivity extends BaseActivity {
//Remove title
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
@ -108,7 +106,6 @@ public class AdminAccountActivity extends BaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
binding.toolbar.setPopupTheme(Helper.popupStyle());
adminVM = new ViewModelProvider(AdminAccountActivity.this).get(AdminVM.class);
if (account_id != null) {
adminVM.getAccount(MainActivity.currentInstance, MainActivity.currentToken, account_id).observe(this, this::initializeView);
@ -272,7 +269,7 @@ public class AdminAccountActivity extends BaseActivity {
}
);
//Load header
MastodonHelper.loadProfileMediaMastodon(binding.bannerPp, adminAccount.account, MastodonHelper.MediaAccountType.HEADER);
MastodonHelper.loadProfileMediaMastodon(AdminAccountActivity.this, binding.bannerPp, adminAccount.account, MastodonHelper.MediaAccountType.HEADER);
//Redraws icon for locked accounts
final float scale = getResources().getDisplayMetrics().density;
if (adminAccount.account.locked) {
@ -295,7 +292,7 @@ public class AdminAccountActivity extends BaseActivity {
final SpannableString content = new SpannableString(getString(R.string.disclaimer_full));
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
content.setSpan(new ForegroundColorSpan(ContextCompat.getColor(AdminAccountActivity.this, R.color.cyanea_accent_reference)), 0, content.length(),
content.setSpan(new ForegroundColorSpan(ThemeHelper.getAttColor(this, R.attr.colorPrimary)), 0, content.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
//This account was moved to another one

View file

@ -22,7 +22,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
@ -30,7 +29,6 @@ import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -38,7 +36,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.google.gson.annotations.SerializedName;
import app.fedilab.android.R;
import app.fedilab.android.activities.BaseActivity;
import app.fedilab.android.activities.BaseBarActivity;
import app.fedilab.android.client.entities.api.admin.AdminDomainBlock;
import app.fedilab.android.databinding.ActivityAdminActionsBinding;
import app.fedilab.android.databinding.PopupAdminFilterAccountsBinding;
@ -49,7 +47,7 @@ import app.fedilab.android.ui.fragment.admin.FragmentAdminAccount;
import app.fedilab.android.ui.fragment.admin.FragmentAdminDomain;
import app.fedilab.android.ui.fragment.admin.FragmentAdminReport;
public class AdminActionActivity extends BaseActivity {
public class AdminActionActivity extends BaseBarActivity {
public static Boolean local = true, remote = true, active = true, pending = true, disabled = true, silenced = true, suspended = true, staff = null, orderByMostRecent = true;
public static Boolean resolved = null, reportLocal = true, reportRemote = true;
@ -81,13 +79,12 @@ public class AdminActionActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
binding = ActivityAdminActionsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter(Helper.BROADCAST_DATA));
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
canGoBack = false;
binding.reports.setOnClickListener(v -> displayTimeline(REPORT));

View file

@ -18,7 +18,6 @@ package app.fedilab.android.activities.admin;
import static app.fedilab.android.helper.Helper.BROADCAST_DATA;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
@ -28,21 +27,19 @@ import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import app.fedilab.android.R;
import app.fedilab.android.activities.BaseActivity;
import app.fedilab.android.activities.BaseBarActivity;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.client.entities.api.admin.AdminDomainBlock;
import app.fedilab.android.databinding.ActivityAdminDomainblockBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.viewmodel.mastodon.AdminVM;
import es.dmoral.toasty.Toasty;
public class AdminDomainBlockActivity extends BaseActivity {
public class AdminDomainBlockActivity extends BaseBarActivity {
private final String[] severityChoices = {"silence", "suspend", "noop"};
@ -52,12 +49,11 @@ public class AdminDomainBlockActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
ActivityAdminDomainblockBinding binding = ActivityAdminDomainblockBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
Bundle b = getIntent().getExtras();
if (b != null) {

View file

@ -19,7 +19,6 @@ import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableString;
@ -55,7 +54,7 @@ import java.util.concurrent.TimeUnit;
import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.activities.BaseActivity;
import app.fedilab.android.activities.BaseBarActivity;
import app.fedilab.android.activities.InstanceProfileActivity;
import app.fedilab.android.activities.MediaActivity;
import app.fedilab.android.client.entities.api.Account;
@ -72,7 +71,7 @@ import app.fedilab.android.viewmodel.mastodon.NodeInfoVM;
import es.dmoral.toasty.Toasty;
public class AdminReportActivity extends BaseActivity {
public class AdminReportActivity extends BaseBarActivity {
private AdminAccount adminAccount;
private Account account;
@ -83,7 +82,7 @@ public class AdminReportActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyTheme(this);
binding = ActivityAdminAccountBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
@ -100,7 +99,6 @@ public class AdminReportActivity extends BaseActivity {
//Remove title
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
@ -109,7 +107,6 @@ public class AdminReportActivity extends BaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
binding.toolbar.setPopupTheme(Helper.popupStyle());
if (account != null) {
initializeView(account);
} else {
@ -291,7 +288,7 @@ public class AdminReportActivity extends BaseActivity {
}
);
//Load header
MastodonHelper.loadProfileMediaMastodon(binding.bannerPp, account, MastodonHelper.MediaAccountType.HEADER);
MastodonHelper.loadProfileMediaMastodon(AdminReportActivity.this, binding.bannerPp, account, MastodonHelper.MediaAccountType.HEADER);
//Redraws icon for locked accounts
final float scale = getResources().getDisplayMetrics().density;
if (account.locked) {
@ -314,7 +311,7 @@ public class AdminReportActivity extends BaseActivity {
final SpannableString content = new SpannableString(getString(R.string.disclaimer_full));
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
content.setSpan(new ForegroundColorSpan(ContextCompat.getColor(AdminReportActivity.this, R.color.cyanea_accent_reference)), 0, content.length(),
content.setSpan(new ForegroundColorSpan(ThemeHelper.getAttColor(this, R.attr.colorPrimary)), 0, content.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
//This account was moved to another one

View file

@ -40,6 +40,7 @@ public class Field implements Serializable {
//Some extra spannable element - They will be filled automatically when fetching the account
private transient ForegroundColorSpan value_span;
private transient ForegroundColorSpan name_span;
public synchronized Spannable getValueSpan(Context context, Account account, WeakReference<View> viewWeakReference) {
@ -53,6 +54,16 @@ public class Field implements Serializable {
return spannable;
}
public synchronized Spannable getLabelSpan(Context context, Account account, WeakReference<View> viewWeakReference) {
Spannable spannable = SpannableHelper.convert(context, name, null, account, null, true, viewWeakReference);
if (name_span != null && spannable != null) {
spannable.setSpan(name_span, 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return spannable;
}
public static class FieldParams implements Serializable {
@SerializedName("name")
public String name;

View file

@ -419,6 +419,7 @@ public class Account extends BaseAccount implements Serializable {
case "PIXELFED":
api = API.PIXELFED;
break;
case "AKKOMA":
case "PLEROMA":
api = API.PLEROMA;
break;

View file

@ -1,132 +0,0 @@
package app.fedilab.android.client.entities.app;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import androidx.preference.PreferenceManager;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HttpsURLConnection;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.sqlite.Sqlite;
public class DomainsBlock {
public static final String LAST_DATE_OF_UPDATE = "LAST_DATE_OF_UPDATE";
public static List<String> trackingDomains = null;
private static void getDomains(Context context) {
if (trackingDomains == null) {
try {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Cursor c = db.query(Sqlite.TABLE_DOMAINS_TRACKING, null, null, null, null, null, null, null);
trackingDomains = cursorToDomain(c);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void updateDomains(Context _mContext) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(_mContext);
String last_date = sharedpreferences.getString(LAST_DATE_OF_UPDATE, null);
Date dateUpdate = new Date(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(10));
Date dateLastUpdate = Helper.stringToDate(_mContext, last_date);
SQLiteDatabase db = Sqlite.getInstance(_mContext.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
if (last_date == null || dateUpdate.after(dateLastUpdate)) {
new Thread(() -> {
try {
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://hosts.fedilab.app/hosts").openConnection();
if (connection.getResponseCode() > HttpsURLConnection.HTTP_MOVED_TEMP) {
return;
}
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
List<String> domains = new ArrayList<>();
while ((line = br.readLine()) != null) {
if (line.startsWith("0.0.0.0 ")) {
try {
domains.add(line.replace("0.0.0.0 ", "").trim());
} catch (Exception e) {
return;
}
}
}
br.close();
connection.disconnect();
insertDomains(db, domains);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(LAST_DATE_OF_UPDATE, Helper.dateToString(new Date()));
editor.apply();
} catch (IOException | DBException e) {
e.printStackTrace();
}
}).start();
} else {
getDomains(_mContext);
}
}
/**
* Insert a domains in db
*
* @param domains {@link List<String>}
* @throws DBException exception with database
*/
private static void insertDomains(SQLiteDatabase db, List<String> domains) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
db.delete(Sqlite.TABLE_DOMAINS_TRACKING, null, null);
DomainsBlock.trackingDomains = new ArrayList<>();
for (String domain : domains) {
ContentValues values = new ContentValues();
values.put(Sqlite.COL_DOMAIN, domain);
//Inserts token
try {
db.insertOrThrow(Sqlite.TABLE_DOMAINS_TRACKING, null, values);
} catch (Exception e) {
e.printStackTrace();
}
DomainsBlock.trackingDomains.add(domain);
}
}
/***
* Method to hydrate domain from database
* @param c Cursor
* @return List<String>
*/
private static List<String> cursorToDomain(Cursor c) {
//No element found
if (c.getCount() == 0) {
c.close();
return null;
}
List<String> domains = new ArrayList<>();
while (c.moveToNext()) {
domains.add(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_DOMAIN)));
}
//Close the cursor
c.close();
//domains list is returned
return domains;
}
}

View file

@ -9,8 +9,6 @@ import android.util.SparseArray;
import android.view.MotionEvent;
import android.view.View;
import androidx.core.content.res.ResourcesCompat;
import java.util.HashSet;
import java.util.Random;
@ -63,7 +61,7 @@ public class CirclesDrawingView extends View {
// Generate bitmap used for background
mCirclePaint = new Paint();
mCirclePaint.setColor(ResourcesCompat.getColor(getContext().getResources(), R.color.cyanea_accent, getContext().getTheme()));
mCirclePaint.setColor(ThemeHelper.getAttColor(ct, R.attr.colorPrimary));
mCirclePaint.setStrokeWidth(10);
mCirclePaint.setStyle(Paint.Style.STROKE);
}

View file

@ -25,7 +25,6 @@ import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import app.fedilab.android.R;
@ -43,7 +42,7 @@ public class CountDrawable extends Drawable {
float mTextSize = context.getResources().getDimension(R.dimen.badge_count_textsize);
mBadgePaint = new Paint();
mBadgePaint.setColor(ContextCompat.getColor(context, R.color.red_1));
mBadgePaint.setColor(ThemeHelper.getAttColor(context, R.attr.colorPrimary));
mBadgePaint.setAntiAlias(true);
mBadgePaint.setStyle(Paint.Style.FILL);

View file

@ -16,8 +16,8 @@ package app.fedilab.android.helper;
import static android.content.Context.DOWNLOAD_SERVICE;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.activities.BaseActivity.currentThemeId;
import static app.fedilab.android.helper.LogoHelper.getNotificationIcon;
import static app.fedilab.android.webview.ProxyHelper.setProxy;
import android.annotation.SuppressLint;
import android.app.Activity;
@ -66,11 +66,8 @@ import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.webkit.CookieManager;
import android.webkit.MimeTypeMap;
import android.webkit.URLUtil;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@ -107,7 +104,6 @@ import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import com.jaredrummler.cyanea.Cyanea;
import org.conscrypt.Conscrypt;
@ -151,7 +147,6 @@ import app.fedilab.android.activities.ComposeActivity;
import app.fedilab.android.activities.LoginActivity;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.activities.ProfileActivity;
import app.fedilab.android.activities.WebviewActivity;
import app.fedilab.android.broadcastreceiver.ToastMessage;
import app.fedilab.android.client.entities.api.Attachment;
import app.fedilab.android.client.entities.api.Status;
@ -168,7 +163,6 @@ import app.fedilab.android.viewmodel.mastodon.AccountsVM;
import app.fedilab.android.viewmodel.mastodon.OauthVM;
import app.fedilab.android.watermark.androidwm.WatermarkBuilder;
import app.fedilab.android.watermark.androidwm.bean.WatermarkText;
import app.fedilab.android.webview.CustomWebview;
import es.dmoral.toasty.Toasty;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
@ -218,6 +212,7 @@ public class Helper {
public static final String ARG_NOTIFICATION_TYPE = "ARG_NOTIFICATION_TYPE";
public static final String ARG_EXCLUDED_NOTIFICATION_TYPE = "ARG_EXCLUDED_NOTIFICATION_TYPE";
public static final String ARG_STATUS = "ARG_STATUS";
public static final String ARG_TIMELINE_REFRESH_ALL = "ARG_TIMELINE_REFRESH_ALL";
public static final String ARG_STATUS_DELETED = "ARG_STATUS_DELETED";
public static final String ARG_STATUS_UPDATED = "ARG_STATUS_UPDATED";
@ -240,7 +235,7 @@ public class Helper {
public static final String ARG_ACCOUNT_ID = "ARG_ACCOUNT_ID";
public static final String ARG_ADMIN_DOMAINBLOCK = "ARG_ADMIN_DOMAINBLOCK";
public static final String ARG_ADMIN_DOMAINBLOCK_DELETE = "ARG_ADMIN_DOMAINBLOCK_DELETE";
public static final String FEDILAB_MUTED_HASHTAGS = "Fedilab muted hashtags";
public static final String ARG_REPORT = "ARG_REPORT";
public static final String ARG_ACCOUNT_MENTION = "ARG_ACCOUNT_MENTION";
public static final String ARG_MINIFIED = "ARG_MINIFIED";
@ -287,7 +282,7 @@ public class Helper {
public static final String VALUE_TRENDS = "VALUE_TRENDS";
public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0";
//public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0";
public static final String REDIRECT_CONTENT_WEB = "fedilab://backtofedilab";
public static final String REDIRECT_CONTENT = "urn:ietf:wg:oauth:2.0:oob";
public static final String APP_OAUTH_SCOPES = "read write";
@ -410,60 +405,6 @@ public class Helper {
patternHashMap = Collections.unmodifiableMap(aMap);
}
/***
* Initialize a CustomWebview
* @param activity Activity - activity containing the webview
* @param webviewId int - webview id
* @param rootView View - the root view that will contain the webview
* @return {@link CustomWebview}
*/
public static CustomWebview initializeWebview(Activity activity, int webviewId, View rootView) {
CustomWebview webView;
if (rootView == null) {
webView = activity.findViewById(webviewId);
} else {
webView = rootView.findViewById(webviewId);
}
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
boolean javascript = sharedpreferences.getBoolean(activity.getString(R.string.SET_JAVASCRIPT), true);
webView.getSettings().setJavaScriptEnabled(javascript);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setDisplayZoomControls(false);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setAllowContentAccess(true);
webView.getSettings().setSaveFormData(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setSupportMultipleWindows(false);
webView.getSettings().setMediaPlaybackRequiresUserGesture(true);
String user_agent = sharedpreferences.getString(activity.getString(R.string.SET_CUSTOM_USER_AGENT), USER_AGENT);
webView.getSettings().setUserAgentString(user_agent);
boolean cookies = sharedpreferences.getBoolean(activity.getString(R.string.SET_COOKIES), false);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptThirdPartyCookies(webView, cookies);
webView.setBackgroundColor(Color.TRANSPARENT);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public Bitmap getDefaultVideoPoster() {
return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
}
});
boolean proxyEnabled = sharedpreferences.getBoolean(activity.getString(R.string.SET_PROXY_ENABLED), false);
if (proxyEnabled) {
String host = sharedpreferences.getString(activity.getString(R.string.SET_PROXY_HOST), "127.0.0.1");
int port = sharedpreferences.getInt(activity.getString(R.string.SET_PROXY_PORT), 8118);
setProxy(activity, webView, host, port, WebviewActivity.class.getName());
}
return webView;
}
/**
* Manage downloads with URLs
@ -717,30 +658,16 @@ public class Helper {
if (url == null) {
return;
}
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean embedded_browser = sharedpreferences.getBoolean(context.getString(R.string.SET_EMBEDDED_BROWSER), true);
if (embedded_browser && !url.toLowerCase().startsWith("gemini://")) {
Intent intent = new Intent(context, WebviewActivity.class);
Bundle b = new Bundle();
String finalUrl = url;
if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://"))
finalUrl = "http://" + url;
b.putString("url", finalUrl);
intent.putExtras(b);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://") && !url.toLowerCase().startsWith("gemini://")) {
url = "http://" + url;
}
intent.setData(Uri.parse(url));
try {
context.startActivity(intent);
} else {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://") && !url.toLowerCase().startsWith("gemini://")) {
url = "http://" + url;
}
intent.setData(Uri.parse(url));
try {
context.startActivity(intent);
} catch (Exception e) {
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
}
@ -940,13 +867,6 @@ public class Helper {
return fragment;
}
public static int dialogStyle() {
return Cyanea.getInstance().isDark() ? R.style.DialogDark : R.style.Dialog;
}
public static int popupStyle() {
return Cyanea.getInstance().isDark() ? R.style.PopupDark : R.style.Popup;
}
/**
* Load a media into a view
@ -1761,7 +1681,7 @@ public class Helper {
httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
else
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
// httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
int responseCode = httpURLConnection.getResponseCode();
// always check HTTP response code first
@ -1851,7 +1771,6 @@ public class Helper {
binding.aboutSupport.setVisibility(View.GONE);
binding.aboutSupportPaypal.setVisibility(View.GONE);
}
binding.accountFollow.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(activity));
binding.accountFollow.setImageResource(R.drawable.ic_baseline_person_add_24);
binding.aboutSupport.setOnClickListener(v -> {
Intent intentLiberapay = new Intent(Intent.ACTION_VIEW);
@ -1992,6 +1911,18 @@ public class Helper {
}
public static int dialogStyle() {
if (R.style.AppThemeBar == currentThemeId || R.style.AppTheme == currentThemeId) {
return R.style.AppThemeAlertDialog;
} else if (R.style.SolarizedAppThemeBar == currentThemeId || R.style.SolarizedAppTheme == currentThemeId) {
return R.style.SolarizedAlertDialog;
} else if (R.style.BlackAppThemeBar == currentThemeId || R.style.BlackAppTheme == currentThemeId) {
return R.style.BlackAlertDialog;
}
return R.style.AppTheme;
}
//Enum that described actions to replace inside a toot content
public enum PatternType {
MENTION,

View file

@ -222,13 +222,17 @@ public class MastodonHelper {
}
public static void loadProfileMediaMastodon(ImageView view, Account account, MediaAccountType type) {
loadProfileMediaMastodon(null, view, account, type);
}
public static void loadProfileMediaMastodon(Activity activity, ImageView view, Account account, MediaAccountType type) {
Context context = view.getContext();
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean disableGif = sharedpreferences.getBoolean(context.getString(R.string.SET_DISABLE_GIF), false);
@DrawableRes int placeholder = type == MediaAccountType.AVATAR ? R.drawable.ic_person : R.drawable.default_banner;
if (Helper.isValidContextForGlide(view.getContext())) {
if (Helper.isValidContextForGlide(activity != null ? activity : context)) {
if (account == null) {
Glide.with(view.getContext())
Glide.with(activity != null ? activity : context)
.asDrawable()
.load(placeholder)
.thumbnail(0.1f)
@ -239,14 +243,14 @@ public class MastodonHelper {
String targetedUrl = disableGif ? (type == MediaAccountType.AVATAR ? account.avatar_static : account.header_static) : (type == MediaAccountType.AVATAR ? account.avatar : account.header);
if (targetedUrl != null) {
if (disableGif || (!targetedUrl.endsWith(".gif"))) {
Glide.with(view.getContext())
Glide.with(activity != null ? activity : context)
.asDrawable()
.load(targetedUrl)
.thumbnail(0.1f)
.placeholder(placeholder)
.into(view);
} else {
Glide.with(view.getContext())
Glide.with(activity != null ? activity : context)
.asGif()
.load(targetedUrl)
.thumbnail(0.1f)
@ -254,7 +258,7 @@ public class MastodonHelper {
.into(view);
}
} else {
Glide.with(view.getContext())
Glide.with(activity != null ? activity : context)
.asDrawable()
.load(placeholder)
.thumbnail(0.1f)
@ -358,9 +362,6 @@ public class MastodonHelper {
dialogBuilder.setView(binding.getRoot());
final AlertDialog alertDialogBoost = dialogBuilder.create();
binding.timePicker.setIs24HourView(true);
binding.dateTimeNext.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(context));
binding.dateTimePrevious.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(context));
binding.dateTimeSet.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(context));
//Buttons management
binding.dateTimeCancel.setOnClickListener(v -> alertDialogBoost.dismiss());
binding.dateTimeNext.setOnClickListener(v -> {

View file

@ -27,6 +27,7 @@ import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.media.MediaRecorder;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
@ -154,7 +155,7 @@ public class MediaHelper {
FileChannel in = null;
FileChannel out = null;
try {
File backupFile = new File(targeted_folder + "/" + fileName);
File backupFile = new File(targeted_folder.getAbsolutePath() + "/" + fileName);
//noinspection ResultOfMethodCallIgnored
backupFile.createNewFile();
fis = new FileInputStream(file);
@ -168,6 +169,7 @@ public class MediaHelper {
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(backupFile);
intent.setDataAndType(uri, mime);
MediaScannerConnection.scanFile(context, new String[]{backupFile.getAbsolutePath()}, null, null);
if (!share) {
notify_user(context, currentAccount, intent, BitmapFactory.decodeResource(context.getResources(),
getMainLogo(context)), Helper.NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));

View file

@ -28,7 +28,6 @@ import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@ -275,31 +274,37 @@ public class PinnedTimelineHelper {
for (MastodonList mastodonList : mastodonLists) {
boolean present = false;
for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) {
if (pinnedTimeline.mastodonList != null && mastodonList.id.compareTo(pinnedTimeline.mastodonList.id) == 0) {
present = true;
break;
}
}
//Needs to be added
if (!present) {
needRedraw = true; //Something changed, redraw must be done
PinnedTimeline pinnedTimeline = new PinnedTimeline();
pinnedTimeline.type = Timeline.TimeLineEnum.LIST;
pinnedTimeline.position = pinned.pinnedTimelines.size();
pinnedTimeline.mastodonList = mastodonList;
pinned.pinnedTimelines.add(pinnedTimeline);
try {
boolean exist = new Pinned(activity).pinnedExist(pinned);
if (exist) {
new Pinned(activity).updatePinned(pinned);
} else {
new Pinned(activity).insertPinned(pinned);
try {
Pinned pinnedAll = new Pinned(activity).getAllPinned(currentAccount);
for (PinnedTimeline pinnedTimeline : pinnedAll.pinnedTimelines) {
if (pinnedTimeline.mastodonList != null && mastodonList.id.compareTo(pinnedTimeline.mastodonList.id) == 0) {
present = true;
break;
}
} catch (DBException e) {
e.printStackTrace();
}
//Needs to be added
if (!present) {
needRedraw = true; //Something changed, redraw must be done
PinnedTimeline pinnedTimeline = new PinnedTimeline();
pinnedTimeline.type = Timeline.TimeLineEnum.LIST;
pinnedTimeline.position = pinnedAll.pinnedTimelines.size();
pinnedTimeline.mastodonList = mastodonList;
pinnedAll.pinnedTimelines.add(pinnedTimeline);
try {
boolean exist = new Pinned(activity).pinnedExist(pinnedAll);
if (exist) {
new Pinned(activity).updatePinned(pinnedAll);
} else {
new Pinned(activity).insertPinned(pinnedAll);
}
} catch (DBException e) {
e.printStackTrace();
}
}
} catch (DBException e) {
e.printStackTrace();
}
}
}
if (!needRedraw) { //if there were no changes with list, no need to update tabs
@ -423,7 +428,7 @@ public class PinnedTimelineHelper {
Pinned finalPinned = pinned;
int finalToRemove1 = toRemove;
activityMainBinding.moreTimelines.setOnClickListener(v -> {
PopupMenu popup = new PopupMenu(new ContextThemeWrapper(activity, Helper.popupStyle()), v);
PopupMenu popup = new PopupMenu(activity, v);
try {
@SuppressLint("PrivateApi")
Method method = popup.getMenu().getClass().getDeclaredMethod("setOptionalIconsVisible", boolean.class);
@ -615,7 +620,7 @@ public class PinnedTimelineHelper {
*/
public static void defaultClick(BaseMainActivity activity, Timeline.TimeLineEnum timeLineEnum, View view, ActivityMainBinding activityMainBinding, int position) {
boolean showExtendedFilter = timeLineEnum == Timeline.TimeLineEnum.HOME;
PopupMenu popup = new PopupMenu(new ContextThemeWrapper(activity, Helper.popupStyle()), view);
PopupMenu popup = new PopupMenu(activity, view);
popup.getMenuInflater()
.inflate(R.menu.option_filter_toots, popup.getMenu());
Menu menu = popup.getMenu();
@ -770,7 +775,7 @@ public class PinnedTimelineHelper {
*/
public static void tagClick(BaseMainActivity activity, Pinned pinned, View view, ActivityMainBinding activityMainBinding, int position, String slug) {
int toRemove = itemToRemoveInBottomMenu(activity);
PopupMenu popup = new PopupMenu(new ContextThemeWrapper(activity, Helper.popupStyle()), view);
PopupMenu popup = new PopupMenu(activity, view);
int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
boolean singleBar = sharedpreferences.getBoolean(activity.getString(R.string.SET_USE_SINGLE_TOPBAR), false);
@ -997,7 +1002,7 @@ public class PinnedTimelineHelper {
*/
public static void instanceClick(BaseMainActivity activity, Pinned pinned, View view, ActivityMainBinding activityMainBinding, int position, String slug) {
PopupMenu popup = new PopupMenu(new ContextThemeWrapper(activity, Helper.popupStyle()), view);
PopupMenu popup = new PopupMenu(activity, view);
int toRemove = itemToRemoveInBottomMenu(activity);
int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);

View file

@ -16,8 +16,7 @@ package app.fedilab.android.helper;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.helper.Helper.USER_AGENT;
import static app.fedilab.android.helper.ThemeHelper.linkColor;
import static app.fedilab.android.ui.drawer.StatusAdapter.sendAction;
import android.content.ClipData;
import android.content.ClipboardManager;
@ -46,6 +45,9 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import androidx.preference.PreferenceManager;
import com.bumptech.glide.Glide;
@ -65,17 +67,21 @@ import java.util.regex.Pattern;
import javax.net.ssl.HttpsURLConnection;
import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.activities.ContextActivity;
import app.fedilab.android.activities.HashTagActivity;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.activities.ProfileActivity;
import app.fedilab.android.client.entities.api.Account;
import app.fedilab.android.client.entities.api.Announcement;
import app.fedilab.android.client.entities.api.Attachment;
import app.fedilab.android.client.entities.api.Emoji;
import app.fedilab.android.client.entities.api.Filter;
import app.fedilab.android.client.entities.api.Mention;
import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.databinding.PopupLinksBinding;
import app.fedilab.android.viewmodel.mastodon.FiltersVM;
import es.dmoral.toasty.Toasty;
public class SpannableHelper {
@ -142,7 +148,7 @@ public class SpannableHelper {
content.removeSpan(span);
}
//Make tags, mentions, groups
interaction(context, content, mentionList);
interaction(context, content, status, mentionList);
//Make all links
linkify(context, content, urlDetails);
linkifyURL(context, content, urlDetails);
@ -245,7 +251,7 @@ public class SpannableHelper {
@Override
public void onLongClick(View view) {
Context mContext = view.getContext();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext, Helper.dialogStyle());
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext);
PopupLinksBinding popupLinksBinding = PopupLinksBinding.inflate(LayoutInflater.from(context));
dialogBuilder.setView(popupLinksBinding.getRoot());
AlertDialog alertDialog = dialogBuilder.create();
@ -263,7 +269,7 @@ public class SpannableHelper {
}
String finalURl1 = finalURl;
popupLinksBinding.displayFullLink.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext, Helper.dialogStyle());
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setMessage(finalURl1);
builder.setTitle(context.getString(R.string.display_full_link));
builder.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss())
@ -314,7 +320,7 @@ public class SpannableHelper {
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) finalUrlCheck.openConnection();
httpsURLConnection.setConnectTimeout(10 * 1000);
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
// httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
httpsURLConnection.setRequestMethod("HEAD");
httpsURLConnection.setInstanceFollowRedirects(false);
if (httpsURLConnection.getResponseCode() == 301 || httpsURLConnection.getResponseCode() == 302) {
@ -340,7 +346,7 @@ public class SpannableHelper {
Handler mainHandler = new Handler(context.getMainLooper());
String finalRedirect = redirect;
Runnable myRunnable = () -> {
AlertDialog.Builder builder1 = new AlertDialog.Builder(view.getContext(), Helper.dialogStyle());
AlertDialog.Builder builder1 = new AlertDialog.Builder(view.getContext());
if (finalRedirect != null) {
builder1.setMessage(context.getString(R.string.redirect_detected, finalURl1, finalRedirect));
builder1.setNegativeButton(R.string.copy_link, (dialog, which) -> {
@ -439,12 +445,6 @@ public class SpannableHelper {
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setColor(linkColor);
}
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
@ -481,7 +481,7 @@ public class SpannableHelper {
@Override
public void onLongClick(View view) {
Context mContext = view.getContext();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext, Helper.dialogStyle());
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext);
PopupLinksBinding popupLinksBinding = PopupLinksBinding.inflate(LayoutInflater.from(context));
dialogBuilder.setView(popupLinksBinding.getRoot());
AlertDialog alertDialog = dialogBuilder.create();
@ -492,7 +492,7 @@ public class SpannableHelper {
}
String finalURl1 = finalURl;
popupLinksBinding.displayFullLink.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext, Helper.dialogStyle());
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setMessage(finalURl1);
builder.setTitle(context.getString(R.string.display_full_link));
builder.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss())
@ -543,7 +543,7 @@ public class SpannableHelper {
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) finalUrlCheck.openConnection();
httpsURLConnection.setConnectTimeout(10 * 1000);
httpsURLConnection.setRequestProperty("http.keepAlive", "false");
httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
//httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
httpsURLConnection.setRequestMethod("HEAD");
httpsURLConnection.setInstanceFollowRedirects(false);
if (httpsURLConnection.getResponseCode() == 301 || httpsURLConnection.getResponseCode() == 302) {
@ -569,7 +569,7 @@ public class SpannableHelper {
Handler mainHandler = new Handler(context.getMainLooper());
String finalRedirect = redirect;
Runnable myRunnable = () -> {
AlertDialog.Builder builder1 = new AlertDialog.Builder(view.getContext(), Helper.dialogStyle());
AlertDialog.Builder builder1 = new AlertDialog.Builder(view.getContext());
if (finalRedirect != null) {
builder1.setMessage(context.getString(R.string.redirect_detected, finalURl1, finalRedirect));
builder1.setNegativeButton(R.string.copy_link, (dialog, which) -> {
@ -667,7 +667,6 @@ public class SpannableHelper {
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setColor(linkColor);
}
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
@ -701,7 +700,6 @@ public class SpannableHelper {
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setColor(linkColor);
}
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
@ -738,14 +736,13 @@ public class SpannableHelper {
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setColor(linkColor);
}
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
}
private static void interaction(Context context, Spannable content, List<Mention> mentions) {
private static void interaction(Context context, Spannable content, Status status, List<Mention> mentions) {
// --- For all patterns defined in Helper class ---
for (Map.Entry<Helper.PatternType, Pattern> entry : Helper.patternHashMap.entrySet()) {
Helper.PatternType patternType = entry.getKey();
@ -764,7 +761,47 @@ public class SpannableHelper {
if (matchStart >= 0 && matchEnd <= content.toString().length() && matchEnd >= matchStart) {
URLSpan[] span = content.getSpans(matchStart, matchEnd, URLSpan.class);
content.removeSpan(span);
content.setSpan(new ClickableSpan() {
content.setSpan(new LongClickableSpan() {
@Override
public void onLongClick(View textView) {
textView.setTag(CLICKABLE_SPAN);
if (patternType == Helper.PatternType.TAG && BaseMainActivity.filterFetched && MainActivity.mainFilters != null) {
String tag = word.trim();
if (!tag.startsWith("#")) {
tag = "#" + tag;
}
Filter fedilabFilter = null;
for (Filter filter : MainActivity.mainFilters) {
if (filter.title.equals(Helper.FEDILAB_MUTED_HASHTAGS)) {
fedilabFilter = filter;
break;
}
}
//Filter for Fedilab doesn't exist we have to create it
if (fedilabFilter == null) {
Filter.FilterParams filterParams = new Filter.FilterParams();
filterParams.title = Helper.FEDILAB_MUTED_HASHTAGS;
filterParams.filter_action = "hide";
filterParams.context = new ArrayList<>();
filterParams.context.add("home");
filterParams.context.add("public");
filterParams.context.add("thread");
filterParams.context.add("account");
String finalTag = tag;
FiltersVM filtersVM = new ViewModelProvider((ViewModelStoreOwner) context).get(FiltersVM.class);
filtersVM.addFilter(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, filterParams)
.observe((LifecycleOwner) context, filter -> {
if (filter != null) {
MainActivity.mainFilters.add(filter);
addTagToFilter(context, finalTag, status, filter);
}
});
} else {
addTagToFilter(context, tag, status, fedilabFilter);
}
}
}
@Override
public void onClick(@NonNull View textView) {
textView.setTag(CLICKABLE_SPAN);
@ -846,14 +883,44 @@ public class SpannableHelper {
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setColor(linkColor);
}
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
}
}
public static void addTagToFilter(Context context, String tag, Status status, Filter filter) {
for (Filter.KeywordsAttributes keywords : filter.keywords) {
if (keywords.keyword.equalsIgnoreCase(tag)) {
return;
}
}
AlertDialog.Builder builder = new AlertDialog.Builder(context, Helper.dialogStyle());
builder.setMessage(context.getString(R.string.mute_tag, tag));
builder
.setPositiveButton(R.string.yes, (dialog, which) -> {
Filter.FilterParams filterParams = new Filter.FilterParams();
filterParams.id = filter.id;
filterParams.keywords = new ArrayList<>();
Filter.KeywordsParams keywordsParams = new Filter.KeywordsParams();
keywordsParams.whole_word = true;
keywordsParams.keyword = tag;
filterParams.keywords.add(keywordsParams);
filterParams.context = filter.context;
FiltersVM filtersVM = new ViewModelProvider((ViewModelStoreOwner) context).get(FiltersVM.class);
filtersVM.editFilter(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, filterParams);
if (status != null) {
status.filteredByApp = filter;
}
sendAction(context, Helper.ARG_TIMELINE_REFRESH_ALL, null, null);
dialog.dismiss();
})
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
.show();
}
/**
* Convert HTML content to text. Also, it handles click on link
* This needs to be run asynchronously
@ -899,7 +966,7 @@ public class SpannableHelper {
int end = spannable.getSpanEnd(quoteSpan);
int flags = spannable.getSpanFlags(quoteSpan);
spannable.removeSpan(quoteSpan);
int colord = ContextCompat.getColor(context, R.color.cyanea_accent_reference);
int colord = ThemeHelper.getAttColor(context, R.attr.colorPrimary);
spannable.setSpan(new CustomQuoteSpan(
ContextCompat.getColor(context, R.color.transparent),
colord,

View file

@ -23,6 +23,7 @@ import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
@ -32,13 +33,10 @@ import android.view.animation.TranslateAnimation;
import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.preference.PreferenceManager;
import com.google.android.material.button.MaterialButton;
import com.jaredrummler.cyanea.Cyanea;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@ -49,11 +47,10 @@ import java.util.LinkedHashMap;
import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.activities.BaseActivity;
public class ThemeHelper {
public static int linkColor;
@ColorInt
public static int getAttColor(Context context, @AttrRes int attColor) {
@ -72,57 +69,7 @@ public class ThemeHelper {
return color;
}
/**
* Initialize colors in a static variable
* Currently link_color cannot be retrieved with getAttColor in ViewModel due to application and theme
*
* @param activity Activity
*/
public static void initiliazeColors(Activity activity) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = activity.getTheme();
theme.resolveAttribute(R.attr.linkColor, typedValue, true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
linkColor = -1;
if (prefs.getBoolean("use_custom_theme", false)) {
linkColor = prefs.getInt("theme_link_color", -1);
}
if (linkColor == -1) {
linkColor = typedValue.data;
}
}
public static void applyTheme(BaseActivity activity) {
if (Cyanea.getInstance().isDark()) {
activity.setTheme(R.style.AppThemeDark);
} else {
activity.setTheme(R.style.AppTheme);
}
}
public static void applyThemeDialog(BaseActivity activity) {
if (Cyanea.getInstance().isDark()) {
activity.setTheme(R.style.DialogDark);
} else {
activity.setTheme(R.style.Dialog);
}
}
public static int getBackgroundColor(Context context) {
if (Cyanea.getInstance().isDark()) {
return ContextCompat.getColor(context, R.color.cyanea_background_dark);
} else {
return ContextCompat.getColor(context, R.color.cyanea_background_light);
}
}
public static void applyThemeBar(BaseActivity activity) {
if (Cyanea.getInstance().isDark()) {
activity.setTheme(R.style.AppThemeBarDark);
} else {
activity.setTheme(R.style.AppThemeBar);
}
}
/**
* Animate two views, the current view will be hidden to left
@ -282,23 +229,6 @@ public class ThemeHelper {
return new ColorStateList(states, colors);
}
public static ColorStateList getButtonActionColorStateList(Context context) {
int[][] states = new int[][]{
new int[]{android.R.attr.state_enabled}, // enabled
new int[]{-android.R.attr.state_enabled}, // disabled
new int[]{-android.R.attr.state_checked}, // unchecked
new int[]{android.R.attr.state_pressed} // pressed
};
int alphaColor = ColorUtils.setAlphaComponent(ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference), 0x33);
int color = ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference);
int[] colors = new int[]{
color,
alphaColor,
color,
color
};
return new ColorStateList(states, colors);
}
/**
@ -319,144 +249,6 @@ public class ThemeHelper {
return new ColorStateList(states, colors);
}
/**
* Allow to set colors for tablayout
*
* @param context - Context
* @return - ColorStateList
*/
public static ColorStateList getColorStateList(Context context) {
int[][] states = new int[][]{
new int[]{android.R.attr.state_selected},
new int[]{-android.R.attr.state_selected},
};
int[] colors = new int[]{
ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference),
getAttColor(context, R.attr.mTextColor)
};
return new ColorStateList(states, colors);
}
/**
* Change all color for a Material button
*
* @param context - Context
* @param materialButton - MaterialButton
*/
public static void changeButtonColor(Context context, MaterialButton materialButton) {
materialButton.setRippleColor(ThemeHelper.getButtonColorStateList(context));
materialButton.setStrokeColor(ThemeHelper.getButtonColorStateList(context));
materialButton.setTextColor(ThemeHelper.getButtonColorStateList(context));
materialButton.setIconTint(ThemeHelper.getButtonColorStateList(context));
materialButton.setBackgroundTintList(ThemeHelper.getBackgroundButtonColorStateList(context));
}
/**
* Allow to set ThumbDrawable colors for SwitchCompat
*
* @param context - Context
* @return - ColorStateList
*/
public static ColorStateList getSwitchCompatThumbDrawable(Context context) {
int[][] states = new int[][]{
new int[]{android.R.attr.state_checked},
new int[]{-android.R.attr.state_checked},
};
int alphaColor = ColorUtils.setAlphaComponent(ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference), 0xee);
int alphaColorUnchecked = ColorUtils.setAlphaComponent(getAttColor(context, R.attr.mTextColor), 0xee);
int[] colors = new int[]{
alphaColor,
alphaColorUnchecked
};
return new ColorStateList(states, colors);
}
/**
* Allow to set TrackDrawable colors for SwitchCompat
*
* @param context - Context
* @return - ColorStateList
*/
public static ColorStateList getSwitchCompatTrackDrawable(Context context) {
int[][] states = new int[][]{
new int[]{android.R.attr.state_checked},
new int[]{-android.R.attr.state_checked},
};
int alphaColor = ColorUtils.setAlphaComponent(ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference), 0x33);
int alphaColorUnchecked = ColorUtils.setAlphaComponent(getAttColor(context, R.attr.mTextColor), 0x33);
int[] colors = new int[]{
alphaColor,
alphaColorUnchecked
};
return new ColorStateList(states, colors);
}
/**
* Allow to set colors for Material buttons inside a toggle group
*
* @param context - Context
* @return - ColorStateList
*/
public static ColorStateList getButtonColorStateList(Context context) {
int[][] states = new int[][]{
new int[]{android.R.attr.state_checked},
new int[]{-android.R.attr.state_checked},
};
int[] colors = new int[]{
ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference),
getAttColor(context, R.attr.mTextColor)
};
return new ColorStateList(states, colors);
}
public static void changeColorOutlineButton(Context context, MaterialButton materialButton) {
if (materialButton != null) {
materialButton.setStrokeColor(ThemeHelper.getButtonOutlineColorStateList(context));
materialButton.setRippleColor(ThemeHelper.getButtonOutlineColorStateList(context));
materialButton.setIconTint(ThemeHelper.getButtonOutlineColorStateList(context));
materialButton.setTextColor(ThemeHelper.getButtonOutlineColorStateList(context));
}
}
/**
* Allow to set colors for Material buttons inside a toggle group
*
* @param context - Context
* @return - ColorStateList
*/
public static ColorStateList getButtonOutlineColorStateList(Context context) {
int[][] states = new int[][]{
new int[]{android.R.attr.state_checked},
new int[]{-android.R.attr.state_checked},
};
int alphaColorUnchecked = ColorUtils.setAlphaComponent(getAttColor(context, R.attr.mTextColor), 0xaa);
int[] colors = new int[]{
ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference),
alphaColorUnchecked
};
return new ColorStateList(states, colors);
}
/**
* Allow to set background colors for Material buttons inside a toggle group
*
* @param context - Context
* @return - ColorStateList
*/
private static ColorStateList getBackgroundButtonColorStateList(Context context) {
int[][] states = new int[][]{
new int[]{android.R.attr.state_checked},
new int[]{-android.R.attr.state_checked},
};
int alphaColor = ColorUtils.setAlphaComponent(ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference), 0x33);
int[] colors = new int[]{
alphaColor,
ContextCompat.getColor(context, R.color.transparent)
};
return new ColorStateList(states, colors);
}
/**
* Allow to change font scale in activities
@ -474,6 +266,27 @@ public class ThemeHelper {
activity.getBaseContext().getResources().updateConfiguration(configuration, metrics);
}
public static void switchTo(String themePref) {
if (themes.LIGHT.name().equals(themePref) || themes.SOLARIZED_LIGHT.name().equals(themePref)) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
} else if (themes.DARK.name().equals(themePref) || themes.SOLARIZED_DARK.name().equals(themePref)) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
}
}
}
public enum themes {
LIGHT,
DARK,
SYSTEM,
SOLARIZED_LIGHT,
SOLARIZED_DARK
}
public interface SlideAnimation {
void onAnimationEnded();

View file

@ -73,7 +73,6 @@ public class TimelineHelper {
*/
public static List<Status> filterStatus(Context context, List<Status> statuses, Timeline.TimeLineEnum filterTimeLineType) {
//A security to make sure filters have been fetched before displaying messages
List<Status> statusesToRemove = new ArrayList<>();
if (!BaseMainActivity.filterFetched) {
MastodonFiltersService mastodonFiltersService = initv2(context);
List<Filter> filterList;
@ -132,12 +131,7 @@ public class TimelineHelper {
content = Html.fromHtml(status.reblog != null ? status.reblog.content : status.content).toString();
Matcher m = p.matcher(content);
if (m.find()) {
if (filter.filter_action.equalsIgnoreCase("warn")) {
status.filteredByApp = filter;
} else {
statusesToRemove.add(status);
}
status.filteredByApp = filter;
continue;
}
if (status.spoiler_text != null) {
@ -148,22 +142,14 @@ public class TimelineHelper {
spoilerText = Html.fromHtml(status.reblog != null ? status.reblog.spoiler_text : status.spoiler_text).toString();
Matcher ms = p.matcher(spoilerText);
if (ms.find()) {
if (filter.filter_action.equalsIgnoreCase("warn")) {
status.filteredByApp = filter;
} else {
statusesToRemove.add(status);
}
status.filteredByApp = filter;
}
}
}
}
}
}
}
if (statuses != null) {
statuses.removeAll(statusesToRemove);
}
return statuses;
}

View file

@ -23,7 +23,7 @@ import android.database.sqlite.SQLiteOpenHelper;
public class Sqlite extends SQLiteOpenHelper {
public static final int DB_VERSION = 6;
public static final int DB_VERSION = 7;
public static final String DB_NAME = "fedilab_db";
//Table of owned accounts
@ -227,6 +227,8 @@ public class Sqlite extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE " + TABLE_STATUS_CACHE + " ADD COLUMN " + COL_SLUG + " TEXT");
db.execSQL("DELETE FROM " + TABLE_STATUS_CACHE);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUICK_LOAD);
case 6:
db.execSQL("DROP TABLE IF EXISTS " + TABLE_DOMAINS_TRACKING);
default:
break;
}

View file

@ -30,7 +30,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
@ -79,12 +78,7 @@ public class AccountAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
// start the new activity
context.startActivity(intent, options.toBundle());
});
ThemeHelper.changeColorOutlineButton(context, accountViewHolder.binding.block);
ThemeHelper.changeColorOutlineButton(context, accountViewHolder.binding.mute);
ThemeHelper.changeColorOutlineButton(context, accountViewHolder.binding.muteNotification);
ThemeHelper.changeColorOutlineButton(context, accountViewHolder.binding.muteTimed);
accountViewHolder.binding.followAction.setIconResource(R.drawable.ic_baseline_person_add_24);
accountViewHolder.binding.followAction.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference)));
if (account.relationShip != null) {
ProfileActivity.action doAction = ProfileActivity.action.FOLLOW;
@ -104,17 +98,16 @@ public class AccountAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
}
if (account.relationShip.following) {
accountViewHolder.binding.followAction.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.red_1)));
accountViewHolder.binding.followAction.setBackgroundTintList(ColorStateList.valueOf(ThemeHelper.getAttColor(context, R.attr.colorError)));
doAction = ProfileActivity.action.UNFOLLOW;
accountViewHolder.binding.followAction.setIconResource(R.drawable.ic_baseline_person_remove_24);
} else if (account.relationShip.requested) {
accountViewHolder.binding.followAction.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.red_1)));
accountViewHolder.binding.followAction.setBackgroundTintList(ColorStateList.valueOf(ThemeHelper.getAttColor(context, R.attr.colorError)));
doAction = ProfileActivity.action.NOTHING;
accountViewHolder.binding.followAction.setEnabled(false);
accountViewHolder.binding.followAction.setIconResource(R.drawable.ic_baseline_hourglass_full_24);
} else {
accountViewHolder.binding.followAction.setIconResource(R.drawable.ic_baseline_person_add_24);
accountViewHolder.binding.followAction.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference)));
}

View file

@ -78,13 +78,18 @@ public class AccountFollowRequestAdapter extends RecyclerView.Adapter<RecyclerVi
AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class);
holderFollow.binding.acceptButton.setOnClickListener(v -> accountsVM.acceptFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id)
.observe((LifecycleOwner) context, relationShip -> {
accountList.remove(position);
notifyItemRemoved(position);
if (accountList.size() > position) {
accountList.remove(position);
notifyItemRemoved(position);
}
}));
holderFollow.binding.rejectButton.setOnClickListener(v -> accountsVM.rejectFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id)
.observe((LifecycleOwner) context, relationShip -> {
accountList.remove(position);
notifyItemRemoved(position);
if (accountList.size() > position) {
accountList.remove(position);
notifyItemRemoved(position);
}
}));
holderFollow.binding.avatar.setOnClickListener(v -> {
Intent intent = new Intent(context, ProfileActivity.class);

View file

@ -22,7 +22,6 @@ import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import androidx.recyclerview.widget.RecyclerView;
@ -37,6 +36,7 @@ import app.fedilab.android.client.entities.api.Account;
import app.fedilab.android.client.entities.api.MastodonList;
import app.fedilab.android.databinding.DrawerAccountListBinding;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
@ -87,7 +87,7 @@ public class AccountListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
if (searchList != null) {
if (accountList.contains(account)) {
holder.binding.listAction.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.red_1)));
holder.binding.listAction.setBackgroundTintList(ColorStateList.valueOf(ThemeHelper.getAttColor(context, R.attr.colorError)));
holder.binding.listAction.setIconResource(R.drawable.ic_baseline_person_remove_alt_1_24);
holder.binding.listAction.setOnClickListener(v -> {
List<String> ids = new ArrayList<>();
@ -97,7 +97,6 @@ public class AccountListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
notifyItemChanged(position);
});
} else {
holder.binding.listAction.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.cyanea_accent_reference)));
holder.binding.listAction.setIconResource(R.drawable.ic_baseline_person_add_alt_1_24);
holder.binding.listAction.setOnClickListener(v -> {
accountList.add(0, account);
@ -108,7 +107,7 @@ public class AccountListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
});
}
} else {
holder.binding.listAction.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.red_1)));
holder.binding.listAction.setBackgroundTintList(ColorStateList.valueOf(ThemeHelper.getAttColor(context, R.attr.colorError)));
holder.binding.listAction.setIconResource(R.drawable.ic_baseline_person_remove_alt_1_24);
holder.binding.listAction.setOnClickListener(v -> {
accountList.remove(account);

View file

@ -28,7 +28,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
@ -61,7 +60,6 @@ import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.widget.ImageViewCompat;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
@ -397,14 +395,14 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
if (holder.getLayoutPosition() == (getItemCount() - 1)) {
if (statusList.size() > statusCount + 1) {
if (canBeRemoved(statusList.get(statusList.size() - 1))) {
holder.binding.addRemoveStatus.setImageResource(R.drawable.ic_compose_thread_remove_status);
holder.binding.addRemoveStatus.setIconResource(R.drawable.ic_compose_thread_remove_status);
holder.binding.addRemoveStatus.setContentDescription(context.getString(R.string.remove_status));
holder.binding.addRemoveStatus.setOnClickListener(v -> {
manageDrafts.onItemDraftDeleted(statusList.get(holder.getLayoutPosition()), holder.getLayoutPosition());
notifyItemChanged((getItemCount() - 1));
});
} else {
holder.binding.addRemoveStatus.setImageResource(R.drawable.ic_compose_thread_add_status);
holder.binding.addRemoveStatus.setIconResource(R.drawable.ic_compose_thread_add_status);
holder.binding.addRemoveStatus.setContentDescription(context.getString(R.string.add_status));
holder.binding.addRemoveStatus.setOnClickListener(v -> {
manageDrafts.onItemDraftAdded(holder.getLayoutPosition());
@ -412,7 +410,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
});
}
} else {
holder.binding.addRemoveStatus.setImageResource(R.drawable.ic_compose_thread_add_status);
holder.binding.addRemoveStatus.setIconResource(R.drawable.ic_compose_thread_add_status);
holder.binding.addRemoveStatus.setContentDescription(context.getString(R.string.add_status));
holder.binding.addRemoveStatus.setOnClickListener(v -> {
manageDrafts.onItemDraftAdded(holder.getLayoutPosition());
@ -941,6 +939,11 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
composeAttachmentItemBinding.buttonOrderDown.setVisibility(View.INVISIBLE);
}
int finalMediaPosition = mediaPosition;
if (attachment.local_path != null && (attachment.local_path.endsWith("png") || attachment.local_path.endsWith("jpg") || attachment.local_path.endsWith("jpeg"))) {
composeAttachmentItemBinding.editPreview.setVisibility(View.VISIBLE);
} else {
composeAttachmentItemBinding.editPreview.setVisibility(View.GONE);
}
composeAttachmentItemBinding.editPreview.setOnClickListener(v -> {
Intent intent = new Intent(context, EditImageActivity.class);
Bundle b = new Bundle();
@ -1096,17 +1099,8 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
int theme_statuses_color = -1;
int theme_text_color = -1;
int theme_text_header_1_line = -1;
int theme_text_header_2_line = -1;
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
if (sharedpreferences.getBoolean("use_custom_theme", false)) {
theme_statuses_color = sharedpreferences.getInt("theme_statuses_color", -1);
theme_text_color = sharedpreferences.getInt("theme_text_color", -1);
theme_text_header_1_line = sharedpreferences.getInt("theme_text_header_1_line", -1);
theme_text_header_2_line = sharedpreferences.getInt("theme_text_header_2_line", -1);
}
if (getItemViewType(position) == TYPE_NORMAL) {
Status status = statusList.get(position);
@ -1135,56 +1129,30 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
holder.binding.spoiler.setText(null);
}
if (theme_statuses_color != -1) {
holder.binding.cardviewContainer.setBackgroundColor(theme_statuses_color);
} else {
holder.binding.cardviewContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.cyanea_primary_dark_reference));
}
if (theme_text_header_2_line != -1) {
holder.binding.username.setTextColor(theme_text_header_2_line);
}
if (theme_text_header_1_line != -1) {
holder.binding.displayName.setTextColor(theme_text_header_1_line);
}
if (theme_text_color != -1) {
holder.binding.statusContent.setTextColor(theme_text_color);
holder.binding.spoiler.setTextColor(theme_text_color);
}
} else if (getItemViewType(position) == TYPE_COMPOSE) {
Status statusDraft = statusList.get(position);
ComposeViewHolder holder = (ComposeViewHolder) viewHolder;
boolean displayEmoji = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_EMOJI), false);
if (displayEmoji) {
holder.binding.buttonEmojiOne.setVisibility(View.VISIBLE);
holder.binding.buttonEmojiOne.setOnClickListener(v -> {
InputMethodManager imm = (InputMethodManager) context.getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(holder.binding.buttonEmojiOne.getWindowToken(), 0);
EmojiManager.install(new EmojiOneProvider());
final EmojiPopup emojiPopup = EmojiPopup.Builder.fromRootView(holder.binding.buttonEmojiOne).setOnEmojiPopupDismissListener(() -> {
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}).build(holder.binding.content);
emojiPopup.toggle();
});
} else {
holder.binding.buttonEmojiOne.setVisibility(View.GONE);
}
holder.binding.visibilityPanel.setBackgroundColor(ContextCompat.getColor(context, R.color.cyanea_primary_dark_reference));
holder.binding.attachmentChoicesPanel.setBackgroundColor(ContextCompat.getColor(context, R.color.cyanea_primary_dark_reference));
holder.binding.buttonEmojiOne.setVisibility(View.VISIBLE);
holder.binding.buttonEmojiOne.setOnClickListener(v -> {
InputMethodManager imm = (InputMethodManager) context.getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(holder.binding.buttonEmojiOne.getWindowToken(), 0);
EmojiManager.install(new EmojiOneProvider());
final EmojiPopup emojiPopup = EmojiPopup.Builder.fromRootView(holder.binding.buttonEmojiOne).setOnEmojiPopupDismissListener(() -> {
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}).build(holder.binding.content);
emojiPopup.toggle();
});
int newInputType = holder.binding.content.getInputType() & (holder.binding.content.getInputType() ^ InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
holder.binding.content.setInputType(newInputType);
int newInputTypeSpoiler = holder.binding.contentSpoiler.getInputType() & (holder.binding.contentSpoiler.getInputType() ^ InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
holder.binding.contentSpoiler.setInputType(newInputTypeSpoiler);
if (theme_statuses_color != -1) {
holder.binding.cardviewContainer.setBackgroundColor(theme_statuses_color);
} else {
holder.binding.cardviewContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.cyanea_primary_dark_reference));
}
holder.binding.buttonAttach.setOnClickListener(v -> {
if (instanceInfo.configuration.media_attachments.supported_mime_types != null) {
if (instanceInfo.getMimeTypeAudio().size() == 0) {
holder.binding.buttonAttachAudio.setEnabled(false);
@ -1200,6 +1168,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
}
}
holder.binding.attachmentChoicesPanel.setVisibility(View.VISIBLE);
holder.binding.buttonAttach.setChecked(false);
});
//Disable buttons to attach media if max has been reached
@ -1254,45 +1223,48 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
switch (statusDraft.visibility.toLowerCase()) {
case "public":
holder.binding.buttonVisibility.setImageResource(R.drawable.ic_compose_visibility_public);
holder.binding.buttonVisibility.setIconResource(R.drawable.ic_compose_visibility_public);
statusDraft.visibility = MastodonHelper.visibility.PUBLIC.name();
break;
case "unlisted":
holder.binding.buttonVisibility.setImageResource(R.drawable.ic_compose_visibility_unlisted);
holder.binding.buttonVisibility.setIconResource(R.drawable.ic_compose_visibility_unlisted);
statusDraft.visibility = MastodonHelper.visibility.UNLISTED.name();
break;
case "private":
holder.binding.buttonVisibility.setImageResource(R.drawable.ic_compose_visibility_private);
holder.binding.buttonVisibility.setIconResource(R.drawable.ic_compose_visibility_private);
statusDraft.visibility = MastodonHelper.visibility.PRIVATE.name();
break;
case "direct":
holder.binding.buttonVisibility.setImageResource(R.drawable.ic_compose_visibility_direct);
holder.binding.buttonVisibility.setIconResource(R.drawable.ic_compose_visibility_direct);
statusDraft.visibility = MastodonHelper.visibility.DIRECT.name();
break;
}
holder.binding.buttonCloseAttachmentPanel.setOnClickListener(v -> holder.binding.attachmentChoicesPanel.setVisibility(View.GONE));
holder.binding.buttonVisibility.setOnClickListener(v -> holder.binding.visibilityPanel.setVisibility(View.VISIBLE));
holder.binding.buttonVisibility.setOnClickListener(v -> {
holder.binding.visibilityPanel.setVisibility(View.VISIBLE);
holder.binding.buttonVisibility.setChecked(false);
});
holder.binding.buttonCloseVisibilityPanel.setOnClickListener(v -> holder.binding.visibilityPanel.setVisibility(View.GONE));
holder.binding.buttonVisibilityDirect.setOnClickListener(v -> {
holder.binding.visibilityPanel.setVisibility(View.GONE);
holder.binding.buttonVisibility.setImageResource(R.drawable.ic_compose_visibility_direct);
holder.binding.buttonVisibility.setIconResource(R.drawable.ic_compose_visibility_direct);
statusDraft.visibility = MastodonHelper.visibility.DIRECT.name();
});
holder.binding.buttonVisibilityPrivate.setOnClickListener(v -> {
holder.binding.visibilityPanel.setVisibility(View.GONE);
holder.binding.buttonVisibility.setImageResource(R.drawable.ic_compose_visibility_private);
holder.binding.buttonVisibility.setIconResource(R.drawable.ic_compose_visibility_private);
statusDraft.visibility = MastodonHelper.visibility.PRIVATE.name();
});
holder.binding.buttonVisibilityUnlisted.setOnClickListener(v -> {
holder.binding.visibilityPanel.setVisibility(View.GONE);
holder.binding.buttonVisibility.setImageResource(R.drawable.ic_compose_visibility_unlisted);
holder.binding.buttonVisibility.setIconResource(R.drawable.ic_compose_visibility_unlisted);
statusDraft.visibility = MastodonHelper.visibility.UNLISTED.name();
});
holder.binding.buttonVisibilityPublic.setOnClickListener(v -> {
holder.binding.visibilityPanel.setVisibility(View.GONE);
holder.binding.buttonVisibility.setImageResource(R.drawable.ic_compose_visibility_public);
holder.binding.buttonVisibility.setIconResource(R.drawable.ic_compose_visibility_public);
statusDraft.visibility = MastodonHelper.visibility.PUBLIC.name();
unlisted_changed = true;
});
@ -1390,11 +1362,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
updateCharacterCount(holder);
}
});
if (statusDraft.poll != null) {
ImageViewCompat.setImageTintList(holder.binding.buttonPoll, ColorStateList.valueOf(ContextCompat.getColor(context, R.color.cyanea_accent)));
} else {
ImageViewCompat.setImageTintList(holder.binding.buttonPoll, null);
}
holder.binding.buttonPost.setEnabled(!statusDraft.submitted);
holder.binding.buttonPost.setOnClickListener(v -> {
@ -1415,6 +1383,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
holder.binding.buttonLanguage.setOnClickListener(v -> {
holder.binding.buttonLanguage.setChecked(false);
Set<String> storedLanguages = sharedpreferences.getStringSet(context.getString(R.string.SET_SELECTED_LANGUAGE), null);
String[] codesArr = new String[0];
String[] languagesArr = new String[0];

View file

@ -88,31 +88,9 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
Conversation conversation = conversationList.get(position);
ConversationHolder holder = (ConversationHolder) viewHolder;
int theme_icons_color = -1;
int theme_statuses_color = -1;
int theme_text_color = -1;
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
if (sharedpreferences.getBoolean("use_custom_theme", false)) {
//Getting custom colors
theme_icons_color = sharedpreferences.getInt("theme_icons_color", -1);
theme_statuses_color = sharedpreferences.getInt("theme_statuses_color", -1);
theme_text_color = sharedpreferences.getInt("theme_text_color", -1);
}
if (theme_icons_color != -1) {
Helper.changeDrawableColor(context, R.drawable.ic_baseline_star_24, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_repeat, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_star_outline, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_person, theme_icons_color);
}
if (theme_statuses_color != -1) {
holder.binding.container.setBackgroundColor(theme_statuses_color);
}
if (theme_text_color != -1) {
holder.binding.statusContent.setTextColor(theme_text_color);
holder.binding.spoiler.setTextColor(theme_text_color);
holder.binding.lastMessageDate.setTextColor(theme_text_color);
}
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
//--- Profile Pictures for participants ---
holder.binding.participantsList.removeAllViews();
@ -160,11 +138,6 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
} else {
holder.binding.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE);
}
if (conversation.cached) {
holder.binding.cacheIndicator.setVisibility(View.VISIBLE);
} else {
holder.binding.cacheIndicator.setVisibility(View.GONE);
}
//---- SPOILER TEXT -----
boolean expand_cw = sharedpreferences.getBoolean(context.getString(R.string.SET_EXPAND_CW), false);
if (conversation.last_status.spoiler_text != null && !conversation.last_status.spoiler_text.trim().isEmpty()) {

View file

@ -77,7 +77,7 @@ public class FieldAdapter extends RecyclerView.Adapter<FieldAdapter.FieldViewHol
holder.binding.value.setMovementMethod(LinkMovementMethod.getInstance());
holder.binding.label.setText(
field.getValueSpan(context, account,
field.getLabelSpan(context, account,
new WeakReference<>(holder.binding.label)),
TextView.BufferType.SPANNABLE);
holder.binding.label.setMovementMethod(LinkMovementMethod.getInstance());

View file

@ -29,7 +29,6 @@ import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.client.entities.api.Filter;
import app.fedilab.android.databinding.DrawerKeywordBinding;
import app.fedilab.android.helper.ThemeHelper;
public class KeywordAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final List<Filter.KeywordsParams> keywordsParamsList;
@ -87,7 +86,6 @@ public class KeywordAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
} else {
holder.binding.mainContainer.setVisibility(View.VISIBLE);
}
holder.binding.deleteKeyword.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(context));
holder.binding.wholeWord.setOnCheckedChangeListener((compoundButton, checked) -> keywordsParams.whole_word = checked);
holder.binding.wholeWord.setChecked(keywordsParams.whole_word != null && keywordsParams.whole_word);
holder.binding.deleteKeyword.setOnClickListener(v -> {

View file

@ -147,22 +147,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
new WeakReference<>(holderFollow.binding.displayName)),
TextView.BufferType.SPANNABLE);
holderFollow.binding.username.setText(String.format("@%s", notification.account.acct));
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
int theme_icons_color = -1;
int theme_text_color = -1;
if (sharedpreferences.getBoolean("use_custom_theme", false)) {
//Getting custom colors
theme_icons_color = sharedpreferences.getInt("theme_icons_color", -1);
theme_text_color = sharedpreferences.getInt("theme_text_color", -1);
}
if (theme_icons_color != -1) {
Helper.changeDrawableColor(context, holderFollow.binding.cacheIndicator, theme_icons_color);
}
if (theme_text_color != -1) {
holderFollow.binding.displayName.setTextColor(theme_text_color);
holderFollow.binding.username.setTextColor(theme_text_color);
holderFollow.binding.title.setTextColor(theme_text_color);
}
holderFollow.binding.rejectButton.setVisibility(View.GONE);
holderFollow.binding.acceptButton.setVisibility(View.GONE);
if (getItemViewType(position) == TYPE_FOLLOW_REQUEST) {
@ -179,16 +164,16 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class);
holderFollow.binding.rejectButton.setOnClickListener(v -> accountsVM.rejectFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, notification.account.id)
.observe((LifecycleOwner) context, relationShip -> {
if (notificationList.size() > position) {
notificationList.remove(position);
notifyItemRemoved(position);
if (notificationList.size() > holderFollow.getBindingAdapterPosition()) {
notificationList.remove(holderFollow.getBindingAdapterPosition());
notifyItemRemoved(holderFollow.getBindingAdapterPosition());
}
}));
holderFollow.binding.acceptButton.setOnClickListener(v -> accountsVM.acceptFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, notification.account.id)
.observe((LifecycleOwner) context, relationShip -> {
if (notificationList.size() > position) {
notificationList.remove(position);
notifyItemRemoved(position);
if (notificationList.size() > holderFollow.getBindingAdapterPosition()) {
notificationList.remove(holderFollow.getBindingAdapterPosition());
notifyItemRemoved(holderFollow.getBindingAdapterPosition());
}
}));
holderFollow.binding.avatar.setOnClickListener(v -> {
@ -232,11 +217,6 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
} else {
holderFollow.binding.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE);
}
if (notification.cached) {
holderFollow.binding.cacheIndicator.setVisibility(View.VISIBLE);
} else {
holderFollow.binding.cacheIndicator.setVisibility(View.GONE);
}
} else if (getItemViewType(position) == TYPE_FILERED) {
StatusAdapter.StatusViewHolder holder = (StatusAdapter.StatusViewHolder) viewHolder;
holder.bindingFiltered.filteredText.setText(context.getString(R.string.filtered_by, notification.filteredByApp.title));
@ -263,7 +243,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
} else if (getItemViewType(position) == TYPE_POLL) {
holderStatus.bindingNotification.status.typeOfNotification.setImageResource(R.drawable.ic_baseline_poll_24);
}
holderStatus.bindingNotification.status.mainContainer.setAlpha(1.0f);
StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class);
SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class);
if (notification.status != null) {
@ -271,7 +251,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
}
statusManagement(context, statusesVM, searchVM, holderStatus, this, null, notification.status, Timeline.TimeLineEnum.NOTIFICATION, false, true, false, null);
holderStatus.bindingNotification.status.dateShort.setText(Helper.dateDiff(context, notification.created_at));
holderStatus.bindingNotification.containerTransparent.setAlpha(.3f);
if (getItemViewType(position) == TYPE_MENTION || getItemViewType(position) == TYPE_STATUS || getItemViewType(position) == TYPE_REACTION) {
holderStatus.bindingNotification.status.actionButtons.setVisibility(View.VISIBLE);
String title = "";
@ -295,21 +275,17 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
// start the new activity
context.startActivity(intent, options.toBundle());
});
holderStatus.bindingNotification.status.mainContainer.setAlpha(.8f);
}
holderStatus.bindingNotification.status.displayName.setText(
notification.account.getSpanDisplayNameTitle(context,
new WeakReference<>(holderStatus.bindingNotification.status.displayName), title),
TextView.BufferType.SPANNABLE);
holderStatus.bindingNotification.status.username.setText(String.format("@%s", notification.account.acct));
holderStatus.bindingNotification.containerTransparent.setAlpha(.1f);
if (notification.status != null && notification.status.visibility.equalsIgnoreCase("direct")) {
holderStatus.bindingNotification.containerTransparent.setVisibility(View.GONE);
} else {
holderStatus.bindingNotification.containerTransparent.setVisibility(View.VISIBLE);
holderStatus.bindingNotification.containerTransparent.setAlpha(.1f);
}
} else {
holderStatus.bindingNotification.containerTransparent.setVisibility(View.VISIBLE);
holderStatus.bindingNotification.status.mainContainer.setAlpha(.7f);
holderStatus.bindingNotification.status.mainContainer.setVisibility(View.VISIBLE);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean displayMedia = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_MEDIA_NOTIFICATION), true);
if (displayMedia && notification.status != null && notification.status.media_attachments != null && notification.status.media_attachments.size() > 0) {

View file

@ -24,6 +24,9 @@ import static app.fedilab.android.BaseMainActivity.regex_public;
import static app.fedilab.android.BaseMainActivity.show_boosts;
import static app.fedilab.android.BaseMainActivity.show_replies;
import static app.fedilab.android.activities.ContextActivity.expand;
import static app.fedilab.android.helper.Helper.ARG_TIMELINE_REFRESH_ALL;
import static app.fedilab.android.helper.Helper.PREF_USER_ID;
import static app.fedilab.android.helper.Helper.PREF_USER_INSTANCE;
import static app.fedilab.android.helper.Helper.PREF_USER_TOKEN;
import android.annotation.SuppressLint;
@ -43,11 +46,8 @@ import android.os.Handler;
import android.os.Looper;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@ -57,6 +57,7 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
@ -125,6 +126,7 @@ import app.fedilab.android.client.entities.app.Timeline;
import app.fedilab.android.databinding.DrawerStatusArtBinding;
import app.fedilab.android.databinding.DrawerStatusBinding;
import app.fedilab.android.databinding.DrawerStatusFilteredBinding;
import app.fedilab.android.databinding.DrawerStatusFilteredHideBinding;
import app.fedilab.android.databinding.DrawerStatusHiddenBinding;
import app.fedilab.android.databinding.DrawerStatusNotificationBinding;
import app.fedilab.android.databinding.DrawerStatusReportBinding;
@ -154,6 +156,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
public static final int STATUS_VISIBLE = 1;
public static final int STATUS_ART = 2;
public static final int STATUS_FILTERED = 3;
public static final int STATUS_FILTERED_HIDE = 4;
private final List<Status> statusList;
private final boolean minified;
private final Timeline.TimeLineEnum timelineType;
@ -375,7 +378,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
boolean confirmFav = sharedpreferences.getBoolean(context.getString(R.string.SET_NOTIF_VALIDATION_FAV), false);
boolean confirmBoost = sharedpreferences.getBoolean(context.getString(R.string.SET_NOTIF_VALIDATION), true);
boolean fullAttachement = sharedpreferences.getBoolean(context.getString(R.string.SET_FULL_PREVIEW), false);
boolean displayBookmark = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_BOOKMARK), false);
boolean displayBookmark = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_BOOKMARK), true);
boolean long_press_media = sharedpreferences.getBoolean(context.getString(R.string.SET_LONG_PRESS_STORE_MEDIA), false);
boolean displayCounters = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_COUNTER_FAV_BOOST), false);
String loadMediaType = sharedpreferences.getString(context.getString(R.string.SET_LOAD_MEDIA_TYPE), "ALWAYS");
@ -494,57 +497,12 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
int truncate_toots_size = sharedpreferences.getInt(context.getString(R.string.SET_TRUNCATE_TOOTS_SIZE), 0);
// boolean display_video_preview = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_VIDEO_PREVIEWS), true);
// boolean isModerator = sharedpreferences.getBoolean(Helper.PREF_IS_MODERATOR, false);
// boolean isAdmin = sharedpreferences.getBoolean(Helper.PREF_IS_ADMINISTRATOR, false);
int theme_icons_color = -1;
int theme_statuses_color = -1;
int theme_boost_header_color = -1;
int theme_text_color = -1;
int theme_text_header_1_line = -1;
int theme_text_header_2_line = -1;
int link_color = -1;
if (sharedpreferences.getBoolean("use_custom_theme", false)) {
//Getting custom colors
theme_icons_color = sharedpreferences.getInt("theme_icons_color", -1);
theme_statuses_color = sharedpreferences.getInt("theme_statuses_color", -1);
theme_boost_header_color = sharedpreferences.getInt("theme_boost_header_color", -1);
theme_text_color = sharedpreferences.getInt("theme_text_color", -1);
theme_text_header_1_line = sharedpreferences.getInt("theme_text_header_1_line", -1);
theme_text_header_2_line = sharedpreferences.getInt("theme_text_header_2_line", -1);
theme_text_color = sharedpreferences.getInt("theme_text_color", -1);
link_color = sharedpreferences.getInt("theme_link_color", -1);
}
if (currentAccount != null && currentAccount.api == Account.API.PLEROMA) {
holder.binding.statusAddCustomEmoji.setVisibility(View.VISIBLE);
holder.binding.statusEmoji.setVisibility(View.VISIBLE);
}
Helper.changeDrawableColor(context, R.drawable.ic_baseline_mode_edit_message_24, R.color.cyanea_accent_reference);
if (theme_icons_color != -1) {
Helper.changeDrawableColor(context, holder.binding.actionButtonReply, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.cacheIndicator, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.statusAddCustomEmoji, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.statusEmoji, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.actionButtonMore, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_baseline_star_24, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_repeat, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.visibility, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_star_outline, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_person, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_bot, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_baseline_reply_16, theme_icons_color);
holder.binding.actionButtonFavorite.setInActiveImageTintColor(theme_icons_color);
holder.binding.actionButtonBookmark.setInActiveImageTintColor(theme_icons_color);
holder.binding.actionButtonBoost.setInActiveImageTintColor(theme_icons_color);
holder.binding.replyCount.setTextColor(theme_icons_color);
} else {
holder.binding.actionButtonFavorite.setInActiveImageTintColor(ThemeHelper.getAttColor(context, R.attr.colorControlNormal));
holder.binding.actionButtonBookmark.setInActiveImageTintColor(ThemeHelper.getAttColor(context, R.attr.colorControlNormal));
holder.binding.actionButtonBoost.setInActiveImageTintColor(ThemeHelper.getAttColor(context, R.attr.colorControlNormal));
}
holder.binding.actionButtonFavorite.pressOnTouch(false);
holder.binding.actionButtonBoost.pressOnTouch(false);
holder.binding.actionButtonBookmark.pressOnTouch(false);
@ -558,12 +516,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.actionButtonBoost.setActiveImageTint(R.color.boost_icon);
holder.binding.actionButtonBookmark.setActiveImageTint(R.color.marked_icon);
if (status.cached) {
holder.binding.cacheIndicator.setVisibility(View.VISIBLE);
} else {
holder.binding.cacheIndicator.setVisibility(View.GONE);
}
if (status.pinned) {
holder.binding.statusPinned.setVisibility(View.VISIBLE);
@ -571,59 +523,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.statusPinned.setVisibility(View.GONE);
}
if (theme_text_header_2_line != -1) {
Pattern hashAcct;
SpannableString wordToSpan;
if (status.reblog != null) {
wordToSpan = new SpannableString("@" + status.reblog.account.acct);
hashAcct = Pattern.compile("(@" + status.reblog.account.acct + ")");
} else {
wordToSpan = new SpannableString("@" + status.account.acct);
hashAcct = Pattern.compile("(@" + status.account.acct + ")");
}
Matcher matcherAcct = hashAcct.matcher(wordToSpan);
while (matcherAcct.find()) {
int matchStart = matcherAcct.start(1);
int matchEnd = matcherAcct.end();
if (wordToSpan.length() >= matchEnd && matchStart < matchEnd && matchStart >= 0) {
wordToSpan.setSpan(new ForegroundColorSpan(theme_text_header_2_line), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
Helper.changeDrawableColor(context, holder.binding.statusBoostIcon, theme_text_header_2_line);
Helper.changeDrawableColor(context, holder.binding.statusPinned, theme_text_header_2_line);
}
if (theme_statuses_color != -1) {
holder.binding.cardviewContainer.setBackgroundColor(theme_statuses_color);
holder.binding.translationLabel.setBackgroundColor(theme_statuses_color);
} else {
holder.binding.cardviewContainer.setBackgroundColor(ThemeHelper.getBackgroundColor(context));
holder.binding.translationLabel.setBackgroundColor(ThemeHelper.getBackgroundColor(context));
}
if (theme_boost_header_color != -1 && status.reblog != null) {
holder.binding.statusBoosterInfo.setBackgroundColor(theme_boost_header_color);
} else {
holder.binding.statusBoosterInfo.setBackgroundColor(0);
}
if (theme_text_color != -1) {
holder.binding.statusContent.setTextColor(theme_text_color);
holder.binding.statusContentTranslated.setTextColor(theme_text_color);
holder.binding.spoiler.setTextColor(theme_text_color);
holder.binding.dateShort.setTextColor(theme_text_color);
holder.binding.poll.pollInfo.setTextColor(theme_text_color);
holder.binding.cardDescription.setTextColor(theme_text_color);
holder.binding.time.setTextColor(theme_text_color);
holder.binding.reblogsCount.setTextColor(theme_text_color);
holder.binding.favoritesCount.setTextColor(theme_text_color);
holder.binding.favoritesCount.setTextColor(theme_text_color);
Helper.changeDrawableColor(context, holder.binding.repeatInfo, theme_text_color);
Helper.changeDrawableColor(context, holder.binding.favInfo, theme_text_color);
Helper.changeDrawableColor(context, R.drawable.ic_baseline_lock_24, theme_text_color);
}
if (link_color != -1) {
holder.binding.cardUrl.setTextColor(link_color);
}
holder.binding.toggleTruncate.setVisibility(View.GONE);
if (status.isFocused) {
@ -724,7 +623,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0);
Status fetchedStatus = results.statuses.get(0);
statusesVM.bookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id)
.observe((LifecycleOwner) context, _status -> manageAction(context, adapter, holder, CrossActionHelper.TypeOfCrossAction.BOOKMARK_ACTION, statusToDeal, _status, true));
} else {
@ -952,13 +851,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
statusToDeal.account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.displayName)),
TextView.BufferType.SPANNABLE);
if (theme_text_header_1_line != -1) {
holder.binding.displayName.setTextColor(theme_text_header_1_line);
}
holder.binding.username.setText(String.format("@%s", statusToDeal.account.acct));
if (theme_text_header_2_line != -1) {
holder.binding.username.setTextColor(theme_text_header_2_line);
}
//final float scale = context.getResources().getDisplayMetrics().density;
final float scale = sharedpreferences.getFloat(context.getString(R.string.SET_FONT_SCALE), 1.1f);
final float scaleIcon = sharedpreferences.getFloat(context.getString(R.string.SET_FONT_SCALE_ICON), 1.1f);
@ -972,12 +865,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
//Button sizes depending of the defined scale
float normalSize = Helper.convertDpToPixel(28, context);
float normalSize2 = Helper.convertDpToPixel(24, context);
holder.binding.actionButtonReply.getLayoutParams().width = (int) (normalSize * scaleIcon);
holder.binding.actionButtonReply.getLayoutParams().height = (int) (normalSize * scaleIcon);
holder.binding.actionButtonReply.requestLayout();
holder.binding.actionButtonBoost.setImageSize((int) (normalSize * scaleIcon));
holder.binding.actionButtonFavorite.setImageSize((int) (normalSize * scaleIcon));
holder.binding.actionButtonBookmark.setImageSize((int) (normalSize * scaleIcon));
holder.binding.actionButtonBookmark.setImageSize((int) (normalSize2 * scaleIcon));
holder.binding.statusAddCustomEmoji.getLayoutParams().width = (int) (normalSize * scaleIcon);
holder.binding.statusAddCustomEmoji.getLayoutParams().height = (int) (normalSize * scaleIcon);
holder.binding.statusAddCustomEmoji.requestLayout();
@ -1130,13 +1025,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
TextView.BufferType.SPANNABLE);
holder.binding.statusBoosterInfo.setVisibility(View.VISIBLE);
if (theme_text_header_1_line != -1) {
holder.binding.statusBoosterDisplayName.setTextColor(theme_text_header_1_line);
}
holder.binding.statusBoosterUsername.setText(String.format("@%s", status.account.acct));
if (theme_text_header_2_line != -1) {
holder.binding.statusBoosterUsername.setTextColor(theme_text_header_2_line);
}
} else {
holder.binding.statusBoosterInfo.setVisibility(View.GONE);
}
@ -1189,6 +1078,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.toggleTruncate.setVisibility(View.GONE);
}
});
} else {
holder.binding.toggleTruncate.setVisibility(View.GONE);
}
if (statusToDeal.translationContent != null) {
holder.binding.containerTrans.setVisibility(View.VISIBLE);
@ -1228,16 +1119,16 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.mediaContainer.setVisibility(View.VISIBLE);
holder.binding.displayMedia.setVisibility(View.GONE);
LayoutMediaBinding layoutMediaBinding = LayoutMediaBinding.inflate(LayoutInflater.from(context), holder.binding.attachmentsList, false);
RelativeLayout.LayoutParams lp;
LinearLayout.LayoutParams lp;
if (fullAttachement) {
lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, MediaHelper.returnMaxHeightForPreviews(context, statusToDeal.media_attachments));
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutMediaBinding.media.setScaleType(ImageView.ScaleType.FIT_CENTER);
} else {
lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, (int) Helper.convertDpToPixel(200, context));
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) Helper.convertDpToPixel(200, context));
layoutMediaBinding.media.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
if (statusToDeal.sensitive) {
Helper.changeDrawableColor(context, layoutMediaBinding.viewHide, R.color.red_1);
Helper.changeDrawableColor(context, layoutMediaBinding.viewHide, ThemeHelper.getAttColor(context, R.attr.colorError));
} else {
Helper.changeDrawableColor(context, layoutMediaBinding.viewHide, R.color.white);
}
@ -1342,14 +1233,17 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
int mediaPosition = 1;
for (Attachment attachment : statusToDeal.media_attachments) {
LayoutMediaBinding layoutMediaBinding = LayoutMediaBinding.inflate(LayoutInflater.from(context), holder.binding.attachmentsList, false);
RelativeLayout.LayoutParams lp;
LinearLayout.LayoutParams lp;
float focusX = 0.f;
float focusY = 0.f;
if (statusToDeal.media_attachments.get(0).meta != null && statusToDeal.media_attachments.get(0).meta.focus != null) {
focusX = statusToDeal.media_attachments.get(0).meta.focus.x;
focusY = statusToDeal.media_attachments.get(0).meta.focus.y;
}
layoutMediaBinding.count.setVisibility(View.VISIBLE);
if (!fullAttachement) {
layoutMediaBinding.count.setText(String.format(Locale.getDefault(), "%d/%d", mediaPosition, statusToDeal.media_attachments.size()));
}
String finalUrl;
if (attachment.url == null) {
finalUrl = attachment.remote_url;
@ -1363,10 +1257,10 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
return true;
});
if (fullAttachement) {
lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, MediaHelper.returnMaxHeightForPreviews(context, statusToDeal.media_attachments));
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutMediaBinding.media.setScaleType(ImageView.ScaleType.FIT_CENTER);
} else {
lp = new RelativeLayout.LayoutParams((int) Helper.convertDpToPixel(200, context), (int) Helper.convertDpToPixel(200, context));
lp = new LinearLayout.LayoutParams((int) Helper.convertDpToPixel(200, context), (int) Helper.convertDpToPixel(200, context));
layoutMediaBinding.media.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
if (attachment.type != null && (attachment.type.equalsIgnoreCase("video") || attachment.type.equalsIgnoreCase("gifv"))) {
@ -1384,7 +1278,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else {
layoutMediaBinding.viewDescription.setVisibility(View.GONE);
}
lp.setMargins(0, 0, (int) Helper.convertDpToPixel(5, context), 0);
if (!mediaObfuscated(statusToDeal) || expand_media) {
layoutMediaBinding.viewHide.setImageResource(R.drawable.ic_baseline_visibility_24);
RequestBuilder<Drawable> requestBuilder = Glide.with(layoutMediaBinding.media.getContext())
@ -1402,7 +1295,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
.into(layoutMediaBinding.media);
}
if (statusToDeal.sensitive) {
Helper.changeDrawableColor(context, layoutMediaBinding.viewHide, R.color.red_1);
Helper.changeDrawableColor(context, layoutMediaBinding.viewHide, ThemeHelper.getAttColor(context, R.attr.colorError));
} else {
Helper.changeDrawableColor(context, layoutMediaBinding.viewHide, R.color.white);
}
@ -1423,11 +1316,23 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
statusToDeal.sensitive = !statusToDeal.sensitive;
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
});
holder.binding.attachmentsList.addView(layoutMediaBinding.getRoot());
if (fullAttachement) {
layoutMediaBinding.getRoot().setPadding(0, 0, 0, 10);
holder.binding.mediaContainer.addView(layoutMediaBinding.getRoot());
} else {
layoutMediaBinding.getRoot().setPadding(0, 0, 10, 0);
holder.binding.attachmentsList.addView(layoutMediaBinding.getRoot());
}
mediaPosition++;
}
holder.binding.mediaContainer.setVisibility(View.GONE);
holder.binding.attachmentsListContainer.setVisibility(View.VISIBLE);
if (!fullAttachement) {
holder.binding.mediaContainer.setVisibility(View.GONE);
holder.binding.attachmentsListContainer.setVisibility(View.VISIBLE);
} else {
holder.binding.mediaContainer.setVisibility(View.VISIBLE);
holder.binding.attachmentsListContainer.setVisibility(View.GONE);
}
}
}
} else {
@ -1513,10 +1418,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
@NonNull LayoutPollItemBinding pollItemBinding = LayoutPollItemBinding.inflate(inflater, holder.binding.poll.rated, true);
double value = ((double) (pollItem.votes_count * 100) / (double) statusToDeal.poll.voters_count);
pollItemBinding.pollItemPercent.setText(String.format("%s %%", (int) value));
if (theme_text_color != -1) {
pollItemBinding.pollItemPercent.setTextColor(theme_text_color);
pollItemBinding.pollItemText.setTextColor(theme_text_color);
}
pollItemBinding.pollItemText.setText(
pollItem.getSpanTitle(context, statusToDeal,
new WeakReference<>(pollItemBinding.pollItemText)),
@ -1529,7 +1430,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
if (ownvotes != null && ownvotes.contains(j)) {
Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_baseline_check_24);
assert img != null;
img.setColorFilter(ContextCompat.getColor(context, R.color.cyanea_accent_reference), PorterDuff.Mode.SRC_IN);
img.setColorFilter(ThemeHelper.getAttColor(context, R.attr.colorPrimary), PorterDuff.Mode.SRC_IN);
img.setBounds(0, 0, (int) (20 * scale + 0.5f), (int) (20 * scale + 0.5f));
pollItemBinding.pollItemText.setCompoundDrawables(null, null, img, null);
}
@ -1546,7 +1447,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
(holder.binding.poll.multipleChoice).removeAllViews();
for (Poll.PollItem pollOption : statusToDeal.poll.options) {
CheckBox cb = new CheckBox(context);
cb.setButtonTintList(ThemeHelper.getButtonColorStateList(context));
cb.setText(
pollOption.getSpanTitle(context, statusToDeal,
new WeakReference<>(cb)),
@ -1560,7 +1460,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
(holder.binding.poll.singleChoiceRadioGroup).removeAllViews();
for (Poll.PollItem pollOption : statusToDeal.poll.options) {
RadioButton rb = new RadioButton(context);
rb.setButtonTintList(ThemeHelper.getButtonColorStateList(context));
rb.setText(
pollOption.getSpanTitle(context, statusToDeal,
new WeakReference<>(rb)),
@ -1614,17 +1513,19 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Status fetchedStatus = results.statuses.get(0);
statusesVM.votePoll(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.poll.id, choice)
.observe((LifecycleOwner) context, poll -> {
int i = 0;
for (Poll.PollItem item : statusToDeal.poll.options) {
if (item.span_title != null) {
poll.options.get(i).span_title = item.span_title;
} else {
poll.options.get(i).span_title = new SpannableString(item.title);
if (poll != null) {
int i = 0;
for (Poll.PollItem item : statusToDeal.poll.options) {
if (item.span_title != null) {
poll.options.get(i).span_title = item.span_title;
} else {
poll.options.get(i).span_title = new SpannableString(item.title);
}
i++;
}
i++;
statusToDeal.poll = poll;
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
}
statusToDeal.poll = poll;
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
});
} else {
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
@ -1734,7 +1635,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
holder.binding.actionButtonMore.setOnClickListener(v -> {
boolean isOwner = statusToDeal.account.id.compareTo(BaseMainActivity.currentUserID) == 0;
PopupMenu popup = new PopupMenu(new ContextThemeWrapper(context, Helper.popupStyle()), holder.binding.actionButtonMore);
PopupMenu popup = new PopupMenu(context, holder.binding.actionButtonMore);
popup.getMenuInflater()
.inflate(R.menu.option_toot, popup.getMenu());
if (statusToDeal.visibility.equals("private") || status.visibility.equals("direct")) {
@ -2047,9 +1948,12 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
MainActivity.currentAccount = account;
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(PREF_USER_TOKEN, account.token);
editor.putString(PREF_USER_INSTANCE, account.instance);
editor.putString(PREF_USER_ID, account.user_id);
editor.commit();
Intent mainActivity = new Intent(context, MainActivity.class);
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.OPEN_WITH_ANOTHER_ACCOUNT);
mainActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
mainActivity.putExtra(Helper.PREF_MESSAGE_URL, statusToDeal.url);
context.startActivity(mainActivity);
((Activity) context).finish();
@ -2084,7 +1988,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0);
Status fetchedStatus = results.statuses.get(0);
Intent intent = new Intent(context, ComposeActivity.class);
intent.putExtra(Helper.ARG_STATUS_REPLY, fetchedStatus);
context.startActivity(intent);
@ -2171,6 +2075,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
if (id != null) {
b.putSerializable(type, id);
}
if (type == ARG_TIMELINE_REFRESH_ALL) {
b.putSerializable(ARG_TIMELINE_REFRESH_ALL, true);
}
Intent intentBC = new Intent(Helper.RECEIVE_STATUS_ACTION);
intentBC.putExtras(b);
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC);
@ -2183,7 +2090,15 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
return STATUS_ART;
} else {
if (statusList.get(position).filteredByApp != null) {
return STATUS_FILTERED;
if (statusList.get(position).filteredByApp.filter_action.equals("warn")) {
return STATUS_FILTERED;
} else { //These messages should not be displayed unless they contain a fetch more button
if (!statusList.get(position).isFetchMore) {
return STATUS_HIDDEN;
} else {
return STATUS_FILTERED_HIDE;
}
}
} else {
return isVisible(timelineType, statusList.get(position)) ? STATUS_VISIBLE : STATUS_HIDDEN;
}
@ -2201,9 +2116,12 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else if (viewType == STATUS_ART) { //Art statuses
DrawerStatusArtBinding itemBinding = DrawerStatusArtBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
return new StatusViewHolder(itemBinding);
} else if (viewType == STATUS_FILTERED) { //Art statuses
} else if (viewType == STATUS_FILTERED) { //Filtered warn
DrawerStatusFilteredBinding itemBinding = DrawerStatusFilteredBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
return new StatusViewHolder(itemBinding);
} else if (viewType == STATUS_FILTERED_HIDE) { //Filtered hide
DrawerStatusFilteredHideBinding itemBinding = DrawerStatusFilteredHideBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
return new StatusViewHolder(itemBinding);
} else { //Classic statuses
if (!minified) {
DrawerStatusBinding itemBinding = DrawerStatusBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
@ -2240,13 +2158,80 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class);
SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class);
statusManagement(context, statusesVM, searchVM, holder, this, statusList, status, timelineType, minified, canBeFederated, checkRemotely, fetchMoreCallBack);
} else if (viewHolder.getItemViewType() == STATUS_FILTERED_HIDE) {
StatusViewHolder holder = (StatusViewHolder) viewHolder;
if (status.isFetchMore && fetchMoreCallBack != null) {
holder.bindingFilteredHide.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE);
holder.bindingFilteredHide.layoutFetchMore.fetchMoreMin.setOnClickListener(v -> {
status.isFetchMore = false;
notifyItemChanged(holder.getBindingAdapterPosition());
if (holder.getBindingAdapterPosition() < statusList.size() - 1) {
String fromId;
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
fromId = statusList.get(holder.getBindingAdapterPosition() + 1).id;
} else {
fromId = status.id;
}
fetchMoreCallBack.onClickMinId(fromId, status);
}
});
holder.bindingFilteredHide.layoutFetchMore.fetchMoreMax.setOnClickListener(v -> {
//We hide the button
status.isFetchMore = false;
String fromId;
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
fromId = statusList.get(holder.getBindingAdapterPosition()).id;
} else {
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
}
fetchMoreCallBack.onClickMaxId(fromId, status);
notifyItemChanged(holder.getBindingAdapterPosition());
});
} else {
holder.bindingFilteredHide.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE);
}
} else if (viewHolder.getItemViewType() == STATUS_FILTERED) {
StatusViewHolder holder = (StatusViewHolder) viewHolder;
holder.bindingFiltered.filteredText.setText(context.getString(R.string.filtered_by, status.filteredByApp.title));
holder.bindingFiltered.displayButton.setOnClickListener(v -> {
status.filteredByApp = null;
notifyItemChanged(position);
});
if (status.isFetchMore && fetchMoreCallBack != null) {
holder.bindingFiltered.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE);
holder.bindingFiltered.layoutFetchMore.fetchMoreMin.setOnClickListener(v -> {
status.isFetchMore = false;
notifyItemChanged(holder.getBindingAdapterPosition());
if (holder.getBindingAdapterPosition() < statusList.size() - 1) {
String fromId;
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
fromId = statusList.get(holder.getBindingAdapterPosition() + 1).id;
} else {
fromId = status.id;
}
fetchMoreCallBack.onClickMinId(fromId, status);
}
});
holder.bindingFiltered.layoutFetchMore.fetchMoreMax.setOnClickListener(v -> {
//We hide the button
status.isFetchMore = false;
String fromId;
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
fromId = statusList.get(holder.getBindingAdapterPosition()).id;
} else {
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
}
fetchMoreCallBack.onClickMaxId(fromId, status);
notifyItemChanged(holder.getBindingAdapterPosition());
});
} else {
holder.bindingFiltered.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE);
}
} else if (viewHolder.getItemViewType() == STATUS_ART) {
StatusViewHolder holder = (StatusViewHolder) viewHolder;
MastodonHelper.loadPPMastodon(holder.bindingArt.artPp, status.account);
@ -2256,7 +2241,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
@Override
public void onGlobalLayout() {
holder.bindingArt.artMedia.getViewTreeObserver().removeOnGlobalLayoutListener(this);
if (status.art_attachment.meta != null) {
if (status.art_attachment.meta != null && status.art_attachment.meta.small != null) {
float viewWidth = holder.bindingArt.artMedia.getWidth();
ConstraintLayout.LayoutParams lp;
float mediaH = status.art_attachment.meta.small.height;
@ -2272,7 +2257,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
});
if (status.art_attachment.meta != null) {
if (status.art_attachment.meta != null && status.art_attachment.meta.small != null) {
float viewWidth = holder.bindingArt.artMedia.getWidth();
ConstraintLayout.LayoutParams lp;
float mediaH = status.art_attachment.meta.small.height;
@ -2290,11 +2275,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
.apply(new RequestOptions().transform(new RoundedCorners((int) Helper.convertDpToPixel(3, context))))
.into(holder.bindingArt.artMedia);
}
holder.bindingArt.artAcct.setText(
holder.bindingArt.artUsername.setText(
status.account.getSpanDisplayName(context,
new WeakReference<>(holder.bindingArt.artAcct)),
new WeakReference<>(holder.bindingArt.artUsername)),
TextView.BufferType.SPANNABLE);
holder.bindingArt.artUsername.setText(String.format(Locale.getDefault(), "@%s", status.account.acct));
holder.bindingArt.artAcct.setText(String.format(Locale.getDefault(), "@%s", status.account.acct));
holder.bindingArt.artPp.setOnClickListener(v -> {
Intent intent = new Intent(context, ProfileActivity.class);
Bundle b = new Bundle();
@ -2347,7 +2332,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
DrawerStatusNotificationBinding bindingNotification;
DrawerStatusArtBinding bindingArt;
DrawerStatusFilteredBinding bindingFiltered;
DrawerStatusFilteredHideBinding bindingFilteredHide;
StatusViewHolder(DrawerStatusBinding itemView) {
super(itemView.getRoot());
binding = itemView;
@ -2380,6 +2365,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
super(itemView.getRoot());
bindingFiltered = itemView;
}
StatusViewHolder(DrawerStatusFilteredHideBinding itemView) {
super(itemView.getRoot());
bindingFilteredHide = itemView;
}
}

View file

@ -15,15 +15,12 @@ package app.fedilab.android.ui.drawer;
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.RecyclerView;
import java.lang.ref.WeakReference;
@ -79,34 +76,6 @@ public class StatusHistoryAdapter extends RecyclerView.Adapter<RecyclerView.View
TextView.BufferType.SPANNABLE);
holder.binding.username.setText(String.format("@%s", status.account.acct));
}
int theme_statuses_color = -1;
int theme_text_color = -1;
int theme_text_header_1_line = -1;
int theme_text_header_2_line = -1;
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
if (sharedpreferences.getBoolean("use_custom_theme", false)) {
theme_statuses_color = sharedpreferences.getInt("theme_statuses_color", -1);
theme_text_color = sharedpreferences.getInt("theme_text_color", -1);
theme_text_header_1_line = sharedpreferences.getInt("theme_text_header_1_line", -1);
theme_text_header_2_line = sharedpreferences.getInt("theme_text_header_2_line", -1);
}
if (theme_statuses_color != -1) {
holder.binding.cardviewContainer.setBackgroundColor(theme_statuses_color);
} else {
holder.binding.cardviewContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.cyanea_primary_dark_reference));
}
if (theme_text_header_2_line != -1) {
holder.binding.username.setTextColor(theme_text_header_2_line);
}
if (theme_text_header_1_line != -1) {
holder.binding.displayName.setTextColor(theme_text_header_1_line);
}
if (theme_text_color != -1) {
holder.binding.statusContent.setTextColor(theme_text_color);
holder.binding.dateModif.setTextColor(theme_text_color);
holder.binding.spoiler.setTextColor(theme_text_color);
}
if (position == 0) {
holder.binding.dateModif.setText(context.getString(R.string.created_message_at, Helper.dateDiffFull(status.created_at)));

View file

@ -18,7 +18,6 @@ package app.fedilab.android.ui.drawer;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -27,7 +26,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import androidx.recyclerview.widget.RecyclerView;
@ -92,7 +90,6 @@ public class SuggestionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
context.startActivity(intent, options.toBundle());
});
holder.binding.followAction.setIconResource(R.drawable.ic_baseline_person_add_24);
holder.binding.followAction.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference)));
if (account == null) {
return;
}

View file

@ -21,7 +21,6 @@ import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.github.mikephil.charting.components.Description;
@ -67,9 +66,6 @@ public class TagAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}
tagViewHolder.binding.tagStats.setText(context.getString(R.string.talking_about, stat));
LineDataSet dataTrending = new LineDataSet(trendsEntry, context.getString(R.string.trending));
dataTrending.setColor(ContextCompat.getColor(context, R.color.cyanea_accent_reference));
dataTrending.setValueTextColor(ContextCompat.getColor(context, R.color.cyanea_accent_reference));
dataTrending.setFillColor(ContextCompat.getColor(context, R.color.cyanea_accent_reference));
dataTrending.setDrawValues(false);
dataTrending.setDrawFilled(true);
dataTrending.setDrawCircles(false);

View file

@ -1,117 +0,0 @@
package app.fedilab.android.ui.drawer;
/* Copyright 2022 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.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.core.content.res.ResourcesCompat;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.client.entities.app.PinnedTimeline;
import app.fedilab.android.client.entities.app.Timeline;
import app.fedilab.android.databinding.DrawerTopMenuItemBinding;
public class TopMenuAdapter extends RecyclerView.Adapter<TopMenuAdapter.TopMenuHolder> {
private final List<PinnedTimeline> pinnedTimelines;
public TopMenuClicked itemListener;
private Context _mContext;
public TopMenuAdapter(List<PinnedTimeline> pinnedTimelines) {
this.pinnedTimelines = pinnedTimelines;
}
public int getCount() {
return pinnedTimelines.size();
}
public PinnedTimeline getItem(int position) {
return pinnedTimelines.get(position);
}
@NonNull
@Override
public TopMenuHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
_mContext = parent.getContext();
DrawerTopMenuItemBinding itemBinding = DrawerTopMenuItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
return new TopMenuHolder(itemBinding);
}
@Override
public void onBindViewHolder(@NonNull TopMenuHolder holder, int position) {
PinnedTimeline pinnedTimeline = pinnedTimelines.get(position);
if (pinnedTimeline.displayed) {
String name = "";
if (pinnedTimeline.type == Timeline.TimeLineEnum.LIST) {
name = pinnedTimeline.mastodonList.title;
} else if (pinnedTimeline.type == Timeline.TimeLineEnum.TAG) {
name = pinnedTimeline.tagTimeline.name;
} else if (pinnedTimeline.type == Timeline.TimeLineEnum.REMOTE) {
name = pinnedTimeline.remoteInstance.host;
}
holder.binding.name.setText(name);
holder.binding.getRoot().setVisibility(View.VISIBLE);
} else {
holder.binding.getRoot().setVisibility(View.GONE);
}
holder.binding.getRoot().setOnClickListener(v -> itemListener.onClick(v, pinnedTimeline, position));
holder.binding.getRoot().setOnLongClickListener(v -> {
itemListener.onLongClick(holder.binding.getRoot(), pinnedTimeline, position);
return true;
});
//Manage item decoration below the text
if (pinnedTimeline.isSelected) {
holder.binding.underline.setVisibility(View.VISIBLE);
holder.binding.name.setTextColor(ResourcesCompat.getColor(_mContext.getResources(), R.color.cyanea_accent, _mContext.getTheme()));
} else {
holder.binding.underline.setVisibility(View.GONE);
int textColor = _mContext.getResources().getColor(android.R.color.primary_text_dark);
holder.binding.name.setTextColor(textColor);
}
}
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return pinnedTimelines.size();
}
public interface TopMenuClicked {
void onClick(View v, PinnedTimeline pinnedTimeline, int position);
void onLongClick(View v, PinnedTimeline pinnedTimeline, int position);
}
static class TopMenuHolder extends RecyclerView.ViewHolder {
DrawerTopMenuItemBinding binding;
TopMenuHolder(DrawerTopMenuItemBinding itemView) {
super(itemView.getRoot());
binding = itemView;
}
}
}

View file

@ -63,7 +63,6 @@ public class FragmentAdminAccount extends Fragment {
}
flagLoading = false;
binding = FragmentPaginationBinding.inflate(inflater, container, false);
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
return binding.getRoot();
}
@ -87,8 +86,7 @@ public class FragmentAdminAccount extends Fragment {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
int c1 = ThemeHelper.getAttColor(requireActivity(), R.attr.colorAccent);
binding.swipeContainer.setColorSchemeColors(
c1, c1, c1
);

View file

@ -112,10 +112,8 @@ public class FragmentAdminDomain extends Fragment {
}
binding = FragmentPaginationBinding.inflate(inflater, container, false);
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
int c1 = ThemeHelper.getAttColor(requireActivity(), R.attr.colorAccent);
binding.swipeContainer.setColorSchemeColors(
c1, c1, c1
);

View file

@ -69,10 +69,8 @@ public class FragmentAdminReport extends Fragment {
}
binding = FragmentPaginationBinding.inflate(inflater, container, false);
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
int c1 = ThemeHelper.getAttColor(requireActivity(), R.attr.colorAccent);
binding.swipeContainer.setColorSchemeColors(
c1, c1, c1
);

View file

@ -19,6 +19,7 @@ import static app.fedilab.android.activities.LoginActivity.apiLogin;
import static app.fedilab.android.activities.LoginActivity.client_idLogin;
import static app.fedilab.android.activities.LoginActivity.client_secretLogin;
import static app.fedilab.android.activities.LoginActivity.currentInstanceLogin;
import static app.fedilab.android.activities.LoginActivity.requestedAdmin;
import static app.fedilab.android.activities.LoginActivity.softwareLogin;
import android.content.Intent;
@ -27,7 +28,6 @@ import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
@ -49,9 +49,7 @@ import java.net.URLEncoder;
import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.activities.LoginActivity;
import app.fedilab.android.activities.ProxyActivity;
import app.fedilab.android.activities.WebviewConnectActivity;
import app.fedilab.android.client.entities.app.Account;
import app.fedilab.android.client.entities.app.InstanceSocial;
import app.fedilab.android.databinding.FragmentLoginMainBinding;
@ -160,6 +158,7 @@ public class FragmentLoginMain extends Fragment {
case "PIXELFED":
apiLogin = Account.API.PIXELFED;
break;
case "AKKOMA":
case "PLEROMA":
apiLogin = Account.API.PLEROMA;
break;
@ -181,43 +180,21 @@ public class FragmentLoginMain extends Fragment {
}
private void showMenu(View v) {
PopupMenu popupMenu = new PopupMenu(new ContextThemeWrapper(requireActivity(), Helper.popupStyle()), binding.menuIcon);
PopupMenu popupMenu = new PopupMenu(requireActivity(), binding.menuIcon);
MenuInflater menuInflater = popupMenu.getMenuInflater();
menuInflater.inflate(R.menu.main_login, popupMenu.getMenu());
MenuItem customTabItem = popupMenu.getMenu().findItem(R.id.action_custom_tabs);
MenuItem adminTabItem = popupMenu.getMenu().findItem(R.id.action_request_admin);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
boolean embedded_browser = sharedpreferences.getBoolean(getString(R.string.SET_EMBEDDED_BROWSER), true);
customTabItem.setChecked(!embedded_browser);
adminTabItem.setChecked(((LoginActivity) requireActivity()).requestedAdmin());
adminTabItem.setChecked(requestedAdmin);
popupMenu.setOnMenuItemClickListener(item -> {
int itemId = item.getItemId();
if (itemId == R.id.action_proxy) {
Intent intent = new Intent(requireActivity(), ProxyActivity.class);
startActivity(intent);
} else if (itemId == R.id.action_custom_tabs) {
boolean checked = !embedded_browser;
item.setChecked(!item.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(getString(R.string.SET_EMBEDDED_BROWSER), checked);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(requireContext()));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
return false;
}
});
editor.apply();
} else if (itemId == R.id.action_request_admin) {
boolean checked = !((LoginActivity) requireActivity()).requestedAdmin();
((LoginActivity) requireActivity()).setAdmin(checked);
item.setChecked(!item.isChecked());
requestedAdmin = item.isChecked();
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(requireContext()));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@ -256,7 +233,7 @@ public class FragmentLoginMain extends Fragment {
} catch (UnsupportedEncodingException e) {
currentInstanceLogin = host;
}
String scopes = ((LoginActivity) requireActivity()).requestedAdmin() ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES;
String scopes = requestedAdmin ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES;
AppsVM appsVM = new ViewModelProvider(requireActivity()).get(AppsVM.class);
appsVM.createApp(currentInstanceLogin, getString(R.string.app_name),
Helper.REDIRECT_CONTENT_WEB,
@ -266,25 +243,14 @@ public class FragmentLoginMain extends Fragment {
if (app != null) {
client_idLogin = app.client_id;
client_secretLogin = app.client_secret;
String redirectUrl = MastodonHelper.authorizeURL(currentInstanceLogin, client_idLogin, ((LoginActivity) requireActivity()).requestedAdmin());
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
boolean embedded_browser = sharedpreferences.getBoolean(getString(R.string.SET_EMBEDDED_BROWSER), true);
if (embedded_browser) {
Intent i = new Intent(requireActivity(), WebviewConnectActivity.class);
i.putExtra("login_url", redirectUrl);
i.putExtra("requestedAdmin", ((LoginActivity) requireActivity()).requestedAdmin());
startActivity(i);
requireActivity().finish();
} else {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse(redirectUrl));
try {
startActivity(intent);
} catch (Exception e) {
Toasty.error(requireActivity(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
String redirectUrl = MastodonHelper.authorizeURL(currentInstanceLogin, client_idLogin, requestedAdmin);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse(redirectUrl));
try {
startActivity(intent);
} catch (Exception e) {
Toasty.error(requireActivity(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
} else {
Toasty.error(requireActivity(), getString(R.string.client_error), Toasty.LENGTH_SHORT).show();

View file

@ -165,7 +165,7 @@ public class FragmentLoginRegisterMastodon extends Fragment {
Locale.getDefault().getLanguage(), null
).observe(requireActivity(), token -> {
if (token != null) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(requireActivity(), Helper.dialogStyle());
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(requireActivity());
dialogBuilder.setCancelable(false);
dialogBuilder.setPositiveButton(R.string.validate, (dialog, which) -> {
dialog.dismiss();

View file

@ -24,7 +24,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.ImageView;
import androidx.annotation.NonNull;
@ -53,9 +52,6 @@ import app.fedilab.android.databinding.FragmentSlideMediaBinding;
import app.fedilab.android.helper.CacheDataSourceFactory;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
import app.fedilab.android.webview.CustomWebview;
import app.fedilab.android.webview.FedilabWebChromeClient;
import app.fedilab.android.webview.FedilabWebViewClient;
public class FragmentMedia extends Fragment {
@ -67,7 +63,6 @@ public class FragmentMedia extends Fragment {
private boolean canSwipe;
private Attachment attachment;
private boolean swipeEnabled;
private CustomWebview webview_video;
private FragmentSlideMediaBinding binding;
@ -90,7 +85,6 @@ public class FragmentMedia extends Fragment {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
swipeEnabled = true;
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
url = attachment.url;
binding.mediaPicture.setOnMatrixChangeListener(rect -> {
@ -218,39 +212,6 @@ public class FragmentMedia extends Fragment {
loadVideo(url, type);
}
break;
case "web":
binding.loader.setVisibility(View.GONE);
binding.mediaPicture.setVisibility(View.GONE);
webview_video = Helper.initializeWebview(requireActivity(), R.id.webview_video, binding.getRoot());
webview_video.setVisibility(View.VISIBLE);
FedilabWebChromeClient fedilabWebChromeClient = new FedilabWebChromeClient(requireActivity(), webview_video, binding.mainMediaFrame, binding.videoLayout);
fedilabWebChromeClient.setOnToggledFullscreen(fullscreen -> {
if (fullscreen) {
binding.videoLayout.setVisibility(View.VISIBLE);
WindowManager.LayoutParams attrs = (requireActivity()).getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
(requireActivity()).getWindow().setAttributes(attrs);
(requireActivity()).getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
} else {
WindowManager.LayoutParams attrs = (requireActivity()).getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
(requireActivity()).getWindow().setAttributes(attrs);
(requireActivity()).getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
binding.videoLayout.setVisibility(View.GONE);
}
});
webview_video.getSettings().setAllowFileAccess(true);
webview_video.setWebChromeClient(fedilabWebChromeClient);
webview_video.getSettings().setDomStorageEnabled(true);
webview_video.getSettings().setAppCacheEnabled(true);
String user_agent = sharedpreferences.getString(getString(R.string.SET_CUSTOM_USER_AGENT), Helper.USER_AGENT);
webview_video.getSettings().setUserAgentString(user_agent);
webview_video.getSettings().setMediaPlaybackRequiresUserGesture(false);
webview_video.setWebViewClient(new FedilabWebViewClient(requireActivity()));
webview_video.loadUrl(attachment.url);
break;
}
}
@ -298,9 +259,6 @@ public class FragmentMedia extends Fragment {
if (player != null) {
player.setPlayWhenReady(false);
}
if (webview_video != null) {
webview_video.onPause();
}
}
@ -313,9 +271,6 @@ public class FragmentMedia extends Fragment {
}
} catch (Exception ignored) {
}
if (webview_video != null) {
webview_video.destroy();
}
if (timer != null) {
timer.cancel();
timer = null;
@ -328,11 +283,6 @@ public class FragmentMedia extends Fragment {
if (player != null) {
player.setPlayWhenReady(true);
}
if (webview_video != null) {
webview_video.onResume();
}
}
private void scheduleStartPostponedTransition(final ImageView imageView) {

View file

@ -50,7 +50,6 @@ public class FragmentComposeSettings extends PreferenceFragmentCompat implements
if (SET_SELECTED_LANGUAGE != null) {
SET_SELECTED_LANGUAGE.getContext().setTheme(Helper.dialogStyle());
}
}
@Override

View file

@ -40,7 +40,6 @@ public class FragmentLanguageSettings extends PreferenceFragmentCompat implement
if (SET_DEFAULT_LOCALE_NEW != null) {
SET_DEFAULT_LOCALE_NEW.getContext().setTheme(Helper.dialogStyle());
}
Preference SET_TRANSLATE_VALUES_RESET = findPreference(getString(R.string.SET_TRANSLATE_VALUES_RESET));
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
if (SET_TRANSLATE_VALUES_RESET != null) {

View file

@ -14,57 +14,14 @@ package app.fedilab.android.ui.fragment.settings;
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import static android.app.Activity.RESULT_OK;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.helper.LogoHelper.getMainLogo;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import com.bumptech.glide.Glide;
import com.jaredrummler.cyanea.Cyanea;
import com.jaredrummler.cyanea.prefs.CyaneaSettingsActivity;
import com.jaredrummler.cyanea.prefs.CyaneaTheme;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.activities.ComposeActivity;
import app.fedilab.android.activities.SettingsActivity;
import app.fedilab.android.databinding.PopupStatusThemeBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import es.dmoral.toasty.Toasty;
@ -72,21 +29,10 @@ import es.dmoral.toasty.Toasty;
public class FragmentThemingSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
private final int PICK_IMPORT_THEME = 5557;
private List<LinkedHashMap<String, String>> listOfThemes;
private SharedPreferences appPref;
private SharedPreferences cyneaPref;
public ActionTheming actionTheming;
private boolean shouldRestart;
@Override
public void onCreatePreferences(Bundle bundle, String s) {
cyneaPref = requireActivity().getSharedPreferences("com.jaredrummler.cyanea", Context.MODE_PRIVATE);
appPref = PreferenceManager.getDefaultSharedPreferences(requireActivity());
createPref();
listOfThemes = ThemeHelper.getContributorsTheme(requireActivity());
shouldRestart = false;
actionTheming = (SettingsActivity) requireActivity();
}
@ -106,225 +52,25 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
if (shouldRestart && actionTheming != null) {
actionTheming.restart();
}
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals("use_custom_theme")) {
createPref();
if (key.compareTo(getString(R.string.SET_THEME_BASE)) == 0) {
ListPreference SET_THEME_BASE = findPreference(getString(R.string.SET_THEME_BASE));
if (SET_THEME_BASE != null) {
ThemeHelper.switchTo(SET_THEME_BASE.getValue());
requireActivity().recreate();
Helper.recreateMainActivity(requireActivity());
}
}
shouldRestart = true;
//TODO: check if can be removed
Helper.recreateMainActivity(requireActivity());
}
public interface ActionTheming {
void restart();
}
@SuppressWarnings("deprecation")
@SuppressLint("ApplySharedPref")
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMPORT_THEME && resultCode == RESULT_OK) {
if (data == null || data.getData() == null) {
Toasty.error(requireActivity(), getString(R.string.theme_file_error), Toast.LENGTH_LONG).show();
return;
}
if (data.getData() != null) {
try {
InputStream inputStream = requireActivity().getContentResolver().openInputStream(data.getData());
readFileAndApply(inputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else {
Toasty.error(requireActivity(), getString(R.string.theme_file_error), Toast.LENGTH_LONG).show();
}
}
}
@SuppressLint("SetTextI18n")
@SuppressWarnings("ConstantConditions")
private void applyColors(PopupStatusThemeBinding binding, int position) {
LinkedHashMap<String, String> themeData = listOfThemes.get(position);
int linksColor = -1;
int iconsColor = -1;
int textColor = -1;
int boostHeaderColor = -1;
int statusColor = -1;
int displayNameColor = -1;
int userNameColor = -1;
int colorAccent = -1;
int backgroundColor = -1;
if (themeData.containsKey("theme_link_color")) {
linksColor = Integer.parseInt(themeData.get("theme_link_color"));
}
if (themeData.containsKey("theme_accent")) {
colorAccent = Integer.parseInt(themeData.get("theme_accent"));
}
if (themeData.containsKey("theme_icons_color")) {
iconsColor = Integer.parseInt(themeData.get("theme_icons_color"));
}
if (themeData.containsKey("theme_text_color")) {
textColor = Integer.parseInt(themeData.get("theme_text_color"));
}
if (themeData.containsKey("theme_boost_header_color")) {
boostHeaderColor = Integer.parseInt(themeData.get("theme_boost_header_color"));
}
if (themeData.containsKey("theme_statuses_color")) {
statusColor = Integer.parseInt(themeData.get("theme_statuses_color"));
}
if (themeData.containsKey("theme_text_header_1_line")) {
displayNameColor = Integer.parseInt(themeData.get("theme_text_header_1_line"));
}
if (themeData.containsKey("theme_text_header_2_line")) {
userNameColor = Integer.parseInt(themeData.get("theme_text_header_2_line"));
}
if (themeData.containsKey("pref_color_background")) {
backgroundColor = Integer.parseInt(themeData.get("pref_color_background"));
}
if (colorAccent != -1) {
binding.spoilerExpand.setTextColor(colorAccent);
binding.cardTitle.setTextColor(colorAccent);
}
if (backgroundColor != -1) {
binding.background.setBackgroundColor(backgroundColor);
}
if (statusColor != -1) {
binding.cardviewContainer.setBackgroundColor(statusColor);
binding.card.setBackgroundColor(statusColor);
}
if (boostHeaderColor != -1) {
binding.headerContainer.setBackgroundColor(boostHeaderColor);
}
if (textColor != -1) {
binding.statusContent.setTextColor(textColor);
binding.statusContentTranslated.setTextColor(textColor);
binding.spoiler.setTextColor(textColor);
binding.cardDescription.setTextColor(textColor);
binding.time.setTextColor(textColor);
binding.reblogsCount.setTextColor(textColor);
binding.favoritesCount.setTextColor(textColor);
Helper.changeDrawableColor(requireActivity(), binding.repeatInfo, textColor);
Helper.changeDrawableColor(requireActivity(), binding.favInfo, textColor);
}
if (linksColor != -1) {
binding.cardUrl.setTextColor(linksColor);
} else {
binding.cardUrl.setTextColor(ThemeHelper.getAttColor(requireActivity(), R.attr.linkColor));
}
if (iconsColor == -1) {
iconsColor = ThemeHelper.getAttColor(requireActivity(), R.attr.iconColor);
}
Helper.changeDrawableColor(requireActivity(), binding.actionButtonReply, iconsColor);
Helper.changeDrawableColor(requireActivity(), binding.actionButtonMore, iconsColor);
Helper.changeDrawableColor(requireActivity(), binding.actionButtonBoost, iconsColor);
Helper.changeDrawableColor(requireActivity(), binding.actionButtonFavorite, iconsColor);
Helper.changeDrawableColor(requireActivity(), R.drawable.ic_person, iconsColor);
if (displayNameColor != -1) {
binding.displayName.setTextColor(displayNameColor);
} else {
binding.displayName.setTextColor(ThemeHelper.getAttColor(requireActivity(), R.attr.statusTextColor));
}
if (userNameColor != -1) {
binding.username.setTextColor(userNameColor);
Helper.changeDrawableColor(requireActivity(), binding.statusBoostIcon, userNameColor);
} else {
binding.username.setTextColor(ThemeHelper.getAttColor(requireActivity(), R.attr.statusTextColor));
Helper.changeDrawableColor(requireActivity(), binding.statusBoostIcon, ThemeHelper.getAttColor(requireActivity(), R.attr.statusTextColor));
}
Glide.with(binding.getRoot().getContext())
.load(R.drawable.fedilab_logo_bubbles)
.into(binding.statusBoosterAvatar);
Glide.with(binding.getRoot().getContext())
.load(R.drawable.fedilab_logo_bubbles)
.into(binding.avatar);
binding.displayName.setText("Fedilab");
binding.username.setText("@apps@toot.fedilab.app");
binding.author.setText(themeData.get("author"));
binding.title.setText(themeData.get("name"));
binding.cardviewContainer.invalidate();
binding.time.setText(Helper.dateToString(new Date()));
}
@SuppressLint("ApplySharedPref")
private void readFileAndApply(InputStream inputStream) {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
String sCurrentLine;
SharedPreferences.Editor appEditor = appPref.edit();
Cyanea.Editor cyaneaEditor = Cyanea.getInstance().edit();
appEditor.putBoolean("use_custom_theme", true);
while ((sCurrentLine = br.readLine()) != null) {
String[] line = sCurrentLine.split(",");
if (line.length > 1) {
String key = line[0];
String value = line[1];
if (key.compareTo("pref_color_navigation_bar") == 0) {
cyaneaEditor.shouldTintNavBar(Boolean.parseBoolean(value));
} else if (key.compareTo("pref_color_background") == 0) {
cyaneaEditor.backgroundDarkLighter(Integer.parseInt(value));
cyaneaEditor.backgroundLightDarker(Integer.parseInt(value));
cyaneaEditor.backgroundDark(Integer.parseInt(value));
cyaneaEditor.backgroundLightLighter(Integer.parseInt(value));
cyaneaEditor.backgroundDarkDarker(Integer.parseInt(value));
cyaneaEditor.background(Integer.parseInt(value));
cyaneaEditor.backgroundDark(Integer.parseInt(value));
cyaneaEditor.backgroundLight(Integer.parseInt(value));
} else if (key.compareTo("base_theme") == 0) {
List<CyaneaTheme> list = CyaneaTheme.Companion.from(requireActivity().getAssets(), "themes/cyanea_themes.json");
CyaneaTheme theme = list.get(Integer.parseInt(value));
cyaneaEditor.baseTheme(theme.getBaseTheme());
if (Integer.parseInt(value) == 0 || Integer.parseInt(value) == 2) {
cyaneaEditor.menuIconColor(ContextCompat.getColor(requireActivity(), R.color.dark_text));
cyaneaEditor.subMenuIconColor(ContextCompat.getColor(requireActivity(), R.color.dark_text));
} else {
cyaneaEditor.menuIconColor(ContextCompat.getColor(requireActivity(), R.color.black));
cyaneaEditor.subMenuIconColor(ContextCompat.getColor(requireActivity(), R.color.black));
}
} else if (key.compareTo("theme_accent") == 0) {
cyaneaEditor.accentLight(Integer.parseInt(value));
cyaneaEditor.accent(Integer.parseInt(value));
cyaneaEditor.accentDark(Integer.parseInt(value));
} else if (key.compareTo("theme_primary") == 0) {
cyaneaEditor.primary(Integer.parseInt(value));
cyaneaEditor.primaryLight(Integer.parseInt(value));
cyaneaEditor.primaryDark(Integer.parseInt(value));
} else {
if (value != null && value.matches("-?\\d+")) {
appEditor.putInt(key, Integer.parseInt(value));
} else {
appEditor.remove(key);
}
}
}
}
appEditor.commit();
cyaneaEditor.apply().recreate(requireActivity());
Helper.recreateMainActivity(requireActivity());
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null) br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
@SuppressWarnings("deprecation")
private void createPref() {
if (getPreferenceScreen() != null) {
getPreferenceScreen().removeAll();
@ -332,273 +78,19 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
addPreferencesFromResource(R.xml.pref_theming);
if (getPreferenceScreen() == null) {
Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
return;
}
Preference launch_custom_theme = findPreference("launch_custom_theme");
if (launch_custom_theme != null) {
launch_custom_theme.setOnPreferenceClickListener(preference -> {
startActivity(new Intent(requireActivity(), CyaneaSettingsActivity.class));
shouldRestart = true;
return false;
});
ListPreference SET_THEME_BASE = findPreference(getString(R.string.SET_THEME_BASE));
if (SET_THEME_BASE != null) {
SET_THEME_BASE.getContext().setTheme(Helper.dialogStyle());
}
Preference contributors_themes = findPreference("contributors_themes");
if (contributors_themes != null) {
contributors_themes.setOnPreferenceClickListener(preference -> {
final int[] currentPosition = {0};
AlertDialog.Builder builderSingle = new AlertDialog.Builder(requireActivity(), Helper.dialogStyle());
builderSingle.setTitle(getString(R.string.select_a_theme));
PopupStatusThemeBinding binding = PopupStatusThemeBinding.inflate(getLayoutInflater(), new LinearLayout(requireActivity()), false);
binding.selectTheme.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
currentPosition[0] = position;
applyColors(binding, position);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
applyColors(binding, 0);
builderSingle.setView(binding.getRoot());
String[] listOfTheme = new String[listOfThemes.size()];
int i = 0;
for (LinkedHashMap<String, String> values : listOfThemes) {
listOfTheme[i] = values.get("name");
i++;
}
//fill data in spinner
ArrayAdapter<String> adapter = new ArrayAdapter<>(requireActivity(), android.R.layout.simple_spinner_dropdown_item, listOfTheme);
binding.selectTheme.setAdapter(adapter);
binding.selectTheme.setSelection(0);
builderSingle.setPositiveButton(R.string.validate, (dialog, which) -> {
try {
String[] list = requireActivity().getAssets().list("themes/contributors");
InputStream is = requireActivity().getAssets().open("themes/contributors/" + list[currentPosition[0]]);
readFileAndApply(is);
} catch (IOException e) {
e.printStackTrace();
}
dialog.dismiss();
});
builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builderSingle.show();
return false;
});
ListPreference SET_THEME_DEFAULT_LIGHT = findPreference(getString(R.string.SET_THEME_DEFAULT_LIGHT));
if (SET_THEME_DEFAULT_LIGHT != null) {
SET_THEME_DEFAULT_LIGHT.getContext().setTheme(Helper.dialogStyle());
}
ListPreference settings_theme = findPreference("settings_theme");
if (settings_theme != null) {
settings_theme.getContext().setTheme(Helper.dialogStyle());
}
Preference theme_link_color = findPreference("theme_link_color");
Preference theme_boost_header_color = findPreference("theme_boost_header_color");
Preference theme_text_header_1_line = findPreference("theme_text_header_1_line");
Preference theme_text_header_2_line = findPreference("theme_text_header_2_line");
Preference theme_statuses_color = findPreference("theme_statuses_color");
Preference theme_icons_color = findPreference("theme_icons_color");
Preference theme_text_color = findPreference("theme_text_color");
Preference pref_import = findPreference("pref_import");
Preference pref_export = findPreference("pref_export");
Preference reset_pref = findPreference("reset_pref");
PreferenceCategory cyanea_preference_category = getPreferenceScreen().findPreference("cyanea_preference_category");
//No custom theme data must be removed
if (!appPref.getBoolean("use_custom_theme", false) && cyanea_preference_category != null) {
if (theme_link_color != null) {
cyanea_preference_category.removePreference(theme_link_color);
}
if (theme_boost_header_color != null) {
cyanea_preference_category.removePreference(theme_boost_header_color);
}
if (theme_text_header_1_line != null) {
cyanea_preference_category.removePreference(theme_text_header_1_line);
}
if (theme_text_header_2_line != null) {
cyanea_preference_category.removePreference(theme_text_header_2_line);
}
if (contributors_themes != null) {
cyanea_preference_category.removePreference(contributors_themes);
}
if (theme_statuses_color != null) {
cyanea_preference_category.removePreference(theme_statuses_color);
}
if (theme_icons_color != null) {
cyanea_preference_category.removePreference(theme_icons_color);
}
if (theme_text_color != null) {
cyanea_preference_category.removePreference(theme_text_color);
}
if (reset_pref != null) {
cyanea_preference_category.removePreference(reset_pref);
}
if (pref_export != null) {
cyanea_preference_category.removePreference(pref_export);
}
}
//These are default values (first three ones)
if (pref_export != null) {
pref_export.setOnPreferenceClickListener(preference -> {
exportColors();
return true;
});
}
if (pref_import != null) {
pref_import.setOnPreferenceClickListener(preference -> {
if (ContextCompat.checkSelfPermission(requireActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(requireActivity(),
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
ComposeActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
return true;
}
shouldRestart = true;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
String[] mimetypes = {"*/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, PICK_IMPORT_THEME);
return true;
});
}
if (reset_pref != null) {
reset_pref.setOnPreferenceClickListener(preference -> {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(requireActivity(), Helper.dialogStyle());
dialogBuilder.setMessage(R.string.reset_color);
dialogBuilder.setPositiveButton(R.string.reset, (dialog, id) -> {
reset();
dialog.dismiss();
setPreferenceScreen(null);
createPref();
});
shouldRestart = true;
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setCancelable(false);
alertDialog.show();
return true;
});
ListPreference SET_THEME_DEFAULT_DARK = findPreference(getString(R.string.SET_THEME_DEFAULT_DARK));
if (SET_THEME_DEFAULT_DARK != null) {
SET_THEME_DEFAULT_DARK.getContext().setTheme(Helper.dialogStyle());
}
}
@SuppressLint("ApplySharedPref")
private void reset() {
SharedPreferences.Editor editor = appPref.edit();
editor.remove("theme_link_color");
editor.remove("theme_boost_header_color");
editor.remove("theme_text_header_1_line");
editor.remove("theme_text_header_2_line");
editor.remove("theme_icons_color");
editor.remove("theme_text_color");
editor.remove("use_custom_theme");
editor.commit();
}
private void exportColors() {
try {
String fileName = "Fedilab_color_export_" + Helper.dateFileToString(getActivity(), new Date()) + ".csv";
String filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
String fullPath = filePath + "/" + fileName;
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fullPath), StandardCharsets.UTF_8));
StringBuilder builder = new StringBuilder();
int theme_boost_header_color = appPref.getInt("theme_boost_header_color", -1);
int theme_text_header_1_line = appPref.getInt("theme_text_header_1_line", -1);
int theme_text_header_2_line = appPref.getInt("theme_text_header_2_line", -1);
int theme_statuses_color = appPref.getInt("theme_statuses_color", -1);
int theme_link_color = appPref.getInt("theme_link_color", -1);
int theme_icons_color = appPref.getInt("theme_icons_color", -1);
int pref_color_background;
if (cyneaPref.getString("base_theme", "DARK").compareTo("DARK") == 0) {
pref_color_background = cyneaPref.getInt("background_dark", -1);
} else {
pref_color_background = cyneaPref.getInt("background_light", -1);
}
boolean pref_color_navigation_bar = cyneaPref.getBoolean("pref_color_navigation_bar", true);
boolean pref_color_status_bar = cyneaPref.getBoolean("pref_color_status_bar", true);
int theme_accent = cyneaPref.getInt("accent", -1);
int theme_text_color = appPref.getInt("theme_text_color", -1);
int theme_primary = cyneaPref.getInt("primary", -1);
int theme = appPref.getInt(getString(R.string.SET_THEME), 0);
builder.append("base_theme").append(',');
builder.append(theme);
builder.append('\n');
builder.append("theme_boost_header_color").append(',');
builder.append(theme_boost_header_color);
builder.append('\n');
builder.append("theme_text_header_1_line").append(',');
builder.append(theme_text_header_1_line);
builder.append('\n');
builder.append("theme_text_header_2_line").append(',');
builder.append(theme_text_header_2_line);
builder.append('\n');
builder.append("theme_statuses_color").append(',');
builder.append(theme_statuses_color);
builder.append('\n');
builder.append("theme_link_color").append(',');
builder.append(theme_link_color);
builder.append('\n');
builder.append("theme_icons_color").append(',');
builder.append(theme_icons_color);
builder.append('\n');
builder.append("pref_color_background").append(',');
builder.append(pref_color_background);
builder.append('\n');
builder.append("pref_color_navigation_bar").append(',');
builder.append(pref_color_navigation_bar);
builder.append('\n');
builder.append("pref_color_status_bar").append(',');
builder.append(pref_color_status_bar);
builder.append('\n');
builder.append("theme_accent").append(',');
builder.append(theme_accent);
builder.append('\n');
builder.append("theme_text_color").append(',');
builder.append(theme_text_color);
builder.append('\n');
builder.append("theme_primary").append(',');
builder.append(theme_primary);
builder.append('\n');
pw.write(builder.toString());
pw.close();
String message = getString(R.string.data_export_theme_success);
Intent intentOpen = new Intent();
intentOpen.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.parse("file://" + fullPath);
intentOpen.setDataAndType(uri, "text/csv");
String title = getString(R.string.data_export_theme);
Helper.notify_user(getActivity(), currentAccount, intentOpen, BitmapFactory.decodeResource(requireActivity().getResources(),
getMainLogo(requireActivity())), Helper.NotifType.BACKUP, title, message);
} catch (Exception e) {
e.printStackTrace();
Toasty.error(requireActivity(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
}
}

View file

@ -40,7 +40,6 @@ import app.fedilab.android.client.entities.app.Timeline;
import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.AccountAdapter;
import app.fedilab.android.ui.pageadapter.FedilabProfileTLPageAdapter;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
@ -74,18 +73,12 @@ public class FragmentMastodonAccount extends Fragment {
}
flagLoading = false;
binding = FragmentPaginationBinding.inflate(inflater, container, false);
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
binding.swipeContainer.setColorSchemeColors(
c1, c1, c1
);
binding.loader.setVisibility(View.VISIBLE);
binding.recyclerView.setVisibility(View.GONE);
accountsVM = new ViewModelProvider(FragmentMastodonAccount.this).get(viewModelKey, AccountsVM.class);

View file

@ -30,7 +30,6 @@ import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.client.entities.api.Announcement;
import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.AnnouncementAdapter;
import app.fedilab.android.viewmodel.mastodon.AnnouncementsVM;
@ -47,12 +46,6 @@ public class FragmentMastodonAnnouncement extends Fragment {
binding = FragmentPaginationBinding.inflate(inflater, container, false);
View root = binding.getRoot();
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
binding.swipeContainer.setColorSchemeColors(
c1, c1, c1
);
announcementsVM = new ViewModelProvider(FragmentMastodonAnnouncement.this).get(AnnouncementsVM.class);
binding.loader.setVisibility(View.VISIBLE);
binding.recyclerView.setVisibility(View.GONE);

View file

@ -43,7 +43,6 @@ import app.fedilab.android.client.entities.app.Timeline;
import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.helper.DividerDecoration;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.StatusAdapter;
import app.fedilab.android.viewmodel.mastodon.StatusesVM;
@ -151,12 +150,6 @@ public class FragmentMastodonContext extends Fragment {
getChildFragmentManager().beginTransaction().remove(this).commit();
}
binding = FragmentPaginationBinding.inflate(inflater, container, false);
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
binding.swipeContainer.setColorSchemeColors(
c1, c1, c1
);
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
statusesVM = new ViewModelProvider(FragmentMastodonContext.this).get(StatusesVM.class);
binding.recyclerView.setNestedScrollingEnabled(true);
this.statuses = new ArrayList<>();

View file

@ -42,7 +42,6 @@ import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.ConversationAdapter;
import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
@ -81,7 +80,6 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
ViewGroup container, Bundle savedInstanceState) {
flagLoading = false;
binding = FragmentPaginationBinding.inflate(inflater, container, false);
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
isViewInitialized = false;
return binding.getRoot();
}
@ -238,12 +236,6 @@ public class FragmentMastodonConversation extends Fragment implements Conversati
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
binding.swipeContainer.setColorSchemeColors(
c1, c1, c1
);
initialConversations = null;
binding.loader.setVisibility(View.VISIBLE);
binding.recyclerView.setVisibility(View.GONE);

View file

@ -34,7 +34,6 @@ import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.client.entities.api.Domains;
import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.DomainBlockAdapter;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
@ -53,18 +52,12 @@ public class FragmentMastodonDomainBlock extends Fragment {
ViewGroup container, Bundle savedInstanceState) {
binding = FragmentPaginationBinding.inflate(inflater, container, false);
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
binding.swipeContainer.setColorSchemeColors(
c1, c1, c1
);
binding.loader.setVisibility(View.VISIBLE);
binding.recyclerView.setVisibility(View.GONE);
accountsVM = new ViewModelProvider(FragmentMastodonDomainBlock.this).get(AccountsVM.class);

View file

@ -50,7 +50,6 @@ import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.NotificationAdapter;
import app.fedilab.android.viewmodel.mastodon.NotificationsVM;
import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
@ -190,12 +189,6 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
notificationType = (NotificationTypeEnum) getArguments().get(Helper.ARG_NOTIFICATION_TYPE);
}
aggregateNotification = false;
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
binding.swipeContainer.setColorSchemeColors(
c1, c1, c1
);
LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION));
return root;

View file

@ -34,7 +34,6 @@ import app.fedilab.android.R;
import app.fedilab.android.client.entities.api.Suggestion;
import app.fedilab.android.client.entities.api.Suggestions;
import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.SuggestionAdapter;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
@ -52,18 +51,12 @@ public class FragmentMastodonSuggestion extends Fragment {
ViewGroup container, Bundle savedInstanceState) {
flagLoading = false;
binding = FragmentPaginationBinding.inflate(inflater, container, false);
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
binding.swipeContainer.setColorSchemeColors(
c1, c1, c1
);
binding.loader.setVisibility(View.VISIBLE);
binding.recyclerView.setVisibility(View.GONE);
accountsVM = new ViewModelProvider(FragmentMastodonSuggestion.this).get(AccountsVM.class);

View file

@ -37,7 +37,6 @@ import app.fedilab.android.client.entities.app.Timeline;
import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.TagAdapter;
import app.fedilab.android.viewmodel.mastodon.SearchVM;
import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
@ -59,18 +58,12 @@ public class FragmentMastodonTag extends Fragment {
}
binding = FragmentPaginationBinding.inflate(inflater, container, false);
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
binding.swipeContainer.setColorSchemeColors(
c1, c1, c1
);
binding.loader.setVisibility(View.VISIBLE);
binding.recyclerView.setVisibility(View.GONE);
router();

View file

@ -61,7 +61,6 @@ import app.fedilab.android.exception.DBException;
import app.fedilab.android.helper.CrossActionHelper;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.drawer.StatusAdapter;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
import app.fedilab.android.viewmodel.mastodon.SearchVM;
@ -98,6 +97,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
Status status_to_delete = (Status) b.getSerializable(Helper.ARG_STATUS_DELETED);
Status status_to_update = (Status) b.getSerializable(Helper.ARG_STATUS_UPDATED);
Status statusPosted = (Status) b.getSerializable(Helper.ARG_STATUS_DELETED);
boolean refreshAll = b.getBoolean(Helper.ARG_TIMELINE_REFRESH_ALL, false);
if (receivedStatus != null && statusAdapter != null) {
int position = getPosition(receivedStatus);
if (position >= 0) {
@ -154,6 +154,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
statusAdapter.notifyItemRemoved(position);
}
}
} else if (refreshAll) {
refreshAllAdapters();
}
}
}
@ -172,6 +174,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private boolean canBeFederated;
private boolean rememberPosition;
private String publicTrendsDomain;
private int lockForResumeCall;
private boolean isNotPinnedTimeline;
//Allow to recreate data when detaching/attaching fragment
public void recreate() {
@ -209,7 +213,12 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
router(null);
}
} else {
router(null);
if (isNotPinnedTimeline && lockForResumeCall == 0) {
router(null);
lockForResumeCall++;
} /*else if (!isNotPinnedTimeline) {
router(null);
}*/
}
if (timelineStatuses != null && timelineStatuses.size() > 0) {
route(DIRECTION.FETCH_NEW, true);
@ -267,6 +276,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
timelinesVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, TimelinesVM.class);
accountsVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, AccountsVM.class);
initialStatuses = null;
lockForResumeCall = 0;
binding.loader.setVisibility(View.VISIBLE);
binding.recyclerView.setVisibility(View.GONE);
max_id = statusReport != null ? statusReport.id : null;
@ -311,6 +321,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
}
publicTrendsDomain = getArguments().getString(Helper.ARG_REMOTE_INSTANCE_STRING, null);
isViewInitialized = getArguments().getBoolean(Helper.ARG_INITIALIZE_VIEW, true);
isNotPinnedTimeline = isViewInitialized;
tagTimeline = (TagTimeline) getArguments().getSerializable(Helper.ARG_TAG_TIMELINE);
accountTimeline = (Account) getArguments().getSerializable(Helper.ARG_ACCOUNT);
exclude_replies = !getArguments().getBoolean(Helper.ARG_SHOW_REPLIES, true);
@ -353,15 +364,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION));
binding = FragmentPaginationBinding.inflate(inflater, container, false);
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
binding.swipeContainer.setColorSchemeColors(
c1, c1, c1
);
return binding.getRoot();
}

View file

@ -27,9 +27,7 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;
@ -46,7 +44,6 @@ import app.fedilab.android.R;
import app.fedilab.android.databinding.FragmentNotificationContainerBinding;
import app.fedilab.android.databinding.PopupNotificationSettingsBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.pageadapter.FedilabNotificationPageAdapter;
import app.fedilab.android.viewmodel.mastodon.NotificationsVM;
import es.dmoral.toasty.Toasty;
@ -93,18 +90,7 @@ public class FragmentNotificationContainer extends Fragment {
PopupNotificationSettingsBinding dialogView = PopupNotificationSettingsBinding.inflate(getLayoutInflater());
dialogBuilder.setView(dialogView.getRoot());
ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayMentions);
ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayFavourites);
ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayReblogs);
ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayPollResults);
ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayUpdatesFromPeople);
ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayFollows);
ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayUpdates);
ThemeHelper.changeButtonColor(requireActivity(), dialogView.displaySignups);
ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayReports);
DrawableCompat.setTintList(DrawableCompat.wrap(dialogView.displayAllCategories.getThumbDrawable()), ThemeHelper.getSwitchCompatThumbDrawable(requireActivity()));
DrawableCompat.setTintList(DrawableCompat.wrap(dialogView.displayAllCategories.getTrackDrawable()), ThemeHelper.getSwitchCompatTrackDrawable(requireActivity()));
dialogView.clearAllNotif.setOnClickListener(v1 -> {
AlertDialog.Builder db = new AlertDialog.Builder(requireActivity(), Helper.dialogStyle());
db.setTitle(R.string.delete_notification_ask_all);
@ -233,8 +219,6 @@ public class FragmentNotificationContainer extends Fragment {
alertDialog.show();
});
binding.tabLayout.setTabTextColors(ThemeHelper.getAttColor(requireActivity(), R.attr.mTextColor), ContextCompat.getColor(requireActivity(), R.color.cyanea_accent_dark_reference));
binding.tabLayout.setTabIconTint(ThemeHelper.getColorStateList(requireActivity()));
binding.viewpagerNotificationContainer.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.tabLayout));
binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override

View file

@ -21,7 +21,6 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import com.google.android.material.tabs.TabLayout;
@ -30,7 +29,6 @@ import app.fedilab.android.R;
import app.fedilab.android.client.entities.api.Account;
import app.fedilab.android.databinding.FragmentProfileTimelinesBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.pageadapter.FedilabProfilePageAdapter;
public class FragmentProfileTimeline extends Fragment {
@ -56,8 +54,6 @@ public class FragmentProfileTimeline extends Fragment {
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.toots)));
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.replies)));
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.media)));
binding.tabLayout.setTabTextColors(ThemeHelper.getAttColor(requireActivity(), R.attr.mTextColor), ContextCompat.getColor(requireActivity(), R.color.cyanea_accent_dark_reference));
binding.tabLayout.setTabIconTint(ThemeHelper.getColorStateList(requireActivity()));
binding.viewpager.setAdapter(new FedilabProfilePageAdapter(getChildFragmentManager(), account, checkRemotely));
binding.viewpager.setOffscreenPageLimit(3);
binding.viewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.tabLayout));

View file

@ -703,6 +703,8 @@ public class AccountsVM extends AndroidViewModel {
Response<RelationShip> muteResponse = muteCall.execute();
if (muteResponse.isSuccessful()) {
relationShip = muteResponse.body();
sendAction(getApplication().getApplicationContext(), Helper.ARG_DELETE_ALL_FOR_ACCOUNT_ID, null, id);
new StatusCache(getApplication().getApplicationContext()).deleteStatusForTargetedAccount(MainActivity.currentInstance, MainActivity.currentUserID, id);
}
} catch (Exception e) {
e.printStackTrace();
@ -1189,6 +1191,7 @@ public class AccountsVM extends AndroidViewModel {
if (acceptFollowResponse.isSuccessful()) {
relationShip = acceptFollowResponse.body();
}
new StatusCache(getApplication().getApplicationContext()).deleteStatus(instance, id);
} catch (Exception e) {
e.printStackTrace();
}
@ -1219,6 +1222,7 @@ public class AccountsVM extends AndroidViewModel {
if (rejectFollowResponse.isSuccessful()) {
relationShip = rejectFollowResponse.body();
}
new StatusCache(getApplication().getApplicationContext()).deleteStatus(instance, id);
} catch (Exception e) {
e.printStackTrace();
}

View file

@ -1,52 +0,0 @@
package app.fedilab.android.webview;
/* Copyright 2021 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.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.util.AttributeSet;
import android.webkit.WebView;
public class CustomWebview extends WebView {
public CustomWebview(Context context) {
super(getFixedContext(context));
}
public CustomWebview(Context context, AttributeSet attrs) {
super(getFixedContext(context), attrs);
}
public CustomWebview(Context context, AttributeSet attrs, int defStyleAttr) {
super(getFixedContext(context), attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CustomWebview(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
}
@SuppressWarnings("deprecation")
public CustomWebview(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing);
}
public static Context getFixedContext(Context context) {
return context.createConfigurationContext(new Configuration());
}
}

View file

@ -1,228 +0,0 @@
package app.fedilab.android.webview;
/* Copyright 2021 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.app.Activity;
import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.view.LayoutInflater;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import app.fedilab.android.R;
public class FedilabWebChromeClient extends WebChromeClient implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener {
private final CustomWebview webView;
private final View activityNonVideoView;
private final ViewGroup activityVideoView;
private final ProgressBar pbar;
private final Activity activity;
private FrameLayout videoViewContainer;
private CustomViewCallback videoViewCallback;
private ToggledFullscreenCallback toggledFullscreenCallback;
private boolean isVideoFullscreen;
public FedilabWebChromeClient(Activity activity, CustomWebview webView, FrameLayout activityNonVideoView, ViewGroup activityVideoView) {
this.activity = activity;
this.isVideoFullscreen = false;
this.webView = webView;
this.pbar = activity.findViewById(R.id.progress_bar);
this.activityNonVideoView = activityNonVideoView;
this.activityVideoView = activityVideoView;
}
@Override
public void onProgressChanged(WebView view, int progress) {
if (pbar != null) {
if (progress < 100 && pbar.getVisibility() == ProgressBar.GONE) {
pbar.setVisibility(ProgressBar.VISIBLE);
}
pbar.setProgress(progress);
if (progress == 100) {
pbar.setVisibility(ProgressBar.GONE);
}
}
}
@Override
public Bitmap getDefaultVideoPoster() {
return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
}
@Override
public void onReceivedIcon(WebView view, Bitmap icon) {
super.onReceivedIcon(view, icon);
LayoutInflater mInflater = LayoutInflater.from(activity);
ActionBar actionBar = ((AppCompatActivity) activity).getSupportActionBar();
if (actionBar != null) {
View webview_actionbar = mInflater.inflate(R.layout.webview_actionbar, new LinearLayout(activity), false);
TextView webview_title = webview_actionbar.findViewById(R.id.webview_title);
webview_title.setText(view.getTitle());
ImageView webview_favicon = webview_actionbar.findViewById(R.id.webview_favicon);
if (icon != null)
webview_favicon.setImageBitmap(icon);
actionBar.setCustomView(webview_actionbar);
actionBar.setDisplayShowCustomEnabled(true);
} else {
activity.setTitle(view.getTitle());
}
}
/**
* Set a callback that will be fired when the video starts or finishes displaying using a custom view (typically full-screen)
*
* @param callback A VideoEnabledWebChromeClient.ToggledFullscreenCallback callback
*/
public void setOnToggledFullscreen(ToggledFullscreenCallback callback) {
this.toggledFullscreenCallback = callback;
}
//FULLSCREEN VIDEO
//Code from https://stackoverflow.com/a/16179544/3197259
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
if (view instanceof FrameLayout) {
if (((AppCompatActivity) activity).getSupportActionBar() != null)
//noinspection ConstantConditions
((AppCompatActivity) activity).getSupportActionBar().hide();
// A video wants to be shown
FrameLayout frameLayout = (FrameLayout) view;
View focusedChild = frameLayout.getFocusedChild();
// Save video related variables
isVideoFullscreen = true;
this.videoViewContainer = frameLayout;
this.videoViewCallback = callback;
// Hide the non-video view, add the video view, and show it
activityNonVideoView.setVisibility(View.INVISIBLE);
activityVideoView.addView(videoViewContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
activityVideoView.setVisibility(View.VISIBLE);
if (focusedChild instanceof android.widget.VideoView) {
// android.widget.VideoView (typically API level <11)
android.widget.VideoView videoView = (android.widget.VideoView) focusedChild;
// Handle all the required events
videoView.setOnCompletionListener(this);
videoView.setOnErrorListener(this);
} else {
// Other classes, including:
// - android.webkit.HTML5VideoFullScreen$VideoSurfaceView, which inherits from android.view.SurfaceView (typically API level 11-18)
// - android.webkit.HTML5VideoFullScreen$VideoTextureView, which inherits from android.view.TextureView (typically API level 11-18)
// - com.android.org.chromium.content.browser.ContentVideoView$VideoSurfaceView, which inherits from android.view.SurfaceView (typically API level 19+)
// Handle HTML5 video ended event only if the class is a SurfaceView
// Test case: TextureView of Sony Xperia T API level 16 doesn't work fullscreen when loading the javascript below
if (webView != null && webView.getSettings().getJavaScriptEnabled() && focusedChild instanceof SurfaceView) {
// Run javascript code that detects the video end and notifies the Javascript interface
String js = "javascript:";
js += "var _ytrp_html5_video_last;";
js += "var _ytrp_html5_video = document.getElementsByTagName('video')[0];";
js += "if (_ytrp_html5_video != undefined && _ytrp_html5_video != _ytrp_html5_video_last) {";
{
js += "_ytrp_html5_video_last = _ytrp_html5_video;";
js += "function _ytrp_html5_video_ended() {";
{
js += "_VideoEnabledWebView.notifyVideoEnd();"; // Must match Javascript interface name and method of VideoEnableWebView
}
js += "}";
js += "_ytrp_html5_video.addEventListener('ended', _ytrp_html5_video_ended);";
}
js += "}";
webView.loadUrl(js);
}
}
// Notify full-screen change
if (toggledFullscreenCallback != null) {
toggledFullscreenCallback.toggledFullscreen(true);
}
}
}
// Available in API level 14+, deprecated in API level 18+
@Override
@SuppressWarnings("deprecation")
public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) {
onShowCustomView(view, callback);
}
@Override
public void onHideCustomView() {
if (((AppCompatActivity) activity).getSupportActionBar() != null)
//noinspection ConstantConditions
((AppCompatActivity) activity).getSupportActionBar().show();
// This method should be manually called on video end in all cases because it's not always called automatically.
// This method must be manually called on back key press (from this class' onBackPressed() method).
if (isVideoFullscreen) {
// Hide the video view, remove it, and show the non-video view
activityVideoView.setVisibility(View.INVISIBLE);
activityVideoView.removeView(videoViewContainer);
activityNonVideoView.setVisibility(View.VISIBLE);
// Call back (only in API level <19, because in API level 19+ with chromium webview it crashes)
if (videoViewCallback != null && !videoViewCallback.getClass().getName().contains(".chromium.")) {
videoViewCallback.onCustomViewHidden();
}
// Reset video related variables
isVideoFullscreen = false;
videoViewContainer = null;
videoViewCallback = null;
// Notify full-screen change
if (toggledFullscreenCallback != null) {
toggledFullscreenCallback.toggledFullscreen(false);
}
}
}
// Video will start loading
@Override
public View getVideoLoadingProgressView() {
return super.getVideoLoadingProgressView();
}
// Video finished playing, only called in the case of android.widget.VideoView (typically API level <11)
@Override
public void onCompletion(MediaPlayer mp) {
onHideCustomView();
}
// Error while playing video, only called in the case of android.widget.VideoView (typically API level <11)
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
return false; // By returning false, onCompletion() will be called
}
public interface ToggledFullscreenCallback {
void toggledFullscreen(boolean fullscreen);
}
}

View file

@ -1,163 +0,0 @@
package app.fedilab.android.webview;
/* Copyright 2021 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 static app.fedilab.android.client.entities.app.DomainsBlock.trackingDomains;
import android.app.Activity;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.URLUtil;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import java.io.ByteArrayInputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.android.BuildConfig;
import app.fedilab.android.R;
import app.fedilab.android.activities.WebviewActivity;
public class FedilabWebViewClient extends WebViewClient {
private final Activity activity;
public List<String> domains = new ArrayList<>();
private int count = 0;
public FedilabWebViewClient(Activity activity) {
this.activity = activity;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public WebResourceResponse shouldInterceptRequest(final WebView view, String url) {
if (trackingDomains != null) {
URI uri;
try {
uri = new URI(url);
String domain = uri.getHost();
if (domain != null) {
domain = domain.startsWith("www.") ? domain.substring(4) : domain;
}
if (domain != null && trackingDomains.contains(domain)) {
if (activity instanceof WebviewActivity) {
count++;
domains.add(url);
((WebviewActivity) activity).setCount(activity, String.valueOf(count));
}
ByteArrayInputStream nothing = new ByteArrayInputStream("".getBytes());
return new WebResourceResponse("text/plain", "utf-8", nothing);
}
} catch (URISyntaxException e) {
try {
if (url.length() > 50) {
url = url.substring(0, 50);
}
uri = new URI(url);
String domain = uri.getHost();
if (domain != null) {
domain = domain.startsWith("www.") ? domain.substring(4) : domain;
}
if (domain != null && trackingDomains.contains(domain)) {
if (activity instanceof WebviewActivity) {
count++;
domains.add(url);
((WebviewActivity) activity).setCount(activity, String.valueOf(count));
}
ByteArrayInputStream nothing = new ByteArrayInputStream("".getBytes());
return new WebResourceResponse("text/plain", "utf-8", nothing);
}
} catch (URISyntaxException ignored) {
}
}
}
return super.shouldInterceptRequest(view, url);
}
public List<String> getDomains() {
return this.domains;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
if (BuildConfig.DONATIONS) {
if (view.getUrl() != null && view.getUrl().endsWith(".onion")) {
handler.proceed();
} else {
super.onReceivedSslError(view, handler, error);
}
} else {
super.onReceivedSslError(view, handler, error);
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (URLUtil.isNetworkUrl(url)) {
return false;
} else {
view.stopLoading();
view.goBack();
}
return false;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
count = 0;
domains = new ArrayList<>();
domains.clear();
ActionBar actionBar = ((AppCompatActivity) activity).getSupportActionBar();
LayoutInflater mInflater = LayoutInflater.from(activity);
if (actionBar != null) {
View webview_actionbar = mInflater.inflate(R.layout.webview_actionbar, new LinearLayout(activity), false);
TextView webview_title = webview_actionbar.findViewById(R.id.webview_title);
webview_title.setText(url);
actionBar.setCustomView(webview_actionbar);
actionBar.setDisplayShowCustomEnabled(true);
} else {
activity.setTitle(url);
}
//Changes the url in webview activity so that it can be opened with an external app
try {
if (activity instanceof WebviewActivity)
((WebviewActivity) activity).setUrl(url);
} catch (Exception ignore) {
}
}
}

View file

@ -1,166 +0,0 @@
package app.fedilab.android.webview;
/* Copyright 2021 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.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.net.Proxy;
import android.util.ArrayMap;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class ProxyHelper {
public static void setProxy(Context context, CustomWebview webview, String host, int port, String applicationClassName) {
setProxyKKPlus(context, webview, host, port, applicationClassName);
}
@SuppressWarnings("all")
private static boolean setProxyICS(CustomWebview webview, String host, int port) {
try {
Class jwcjb = Class.forName("android.webkit.JWebCoreJavaBridge");
Class params[] = new Class[1];
params[0] = Class.forName("android.net.ProxyProperties");
Method updateProxyInstance = jwcjb.getDeclaredMethod("updateProxy", params);
Class wv = Class.forName("android.webkit.WebView");
Field mWebViewCoreField = wv.getDeclaredField("mWebViewCore");
Object mWebViewCoreFieldInstance = getFieldValueSafely(mWebViewCoreField, webview);
Class wvc = Class.forName("android.webkit.WebViewCore");
Field mBrowserFrameField = wvc.getDeclaredField("mBrowserFrame");
Object mBrowserFrame = getFieldValueSafely(mBrowserFrameField, mWebViewCoreFieldInstance);
Class bf = Class.forName("android.webkit.BrowserFrame");
Field sJavaBridgeField = bf.getDeclaredField("sJavaBridge");
Object sJavaBridge = getFieldValueSafely(sJavaBridgeField, mBrowserFrame);
Class ppclass = Class.forName("android.net.ProxyProperties");
Class pparams[] = new Class[3];
pparams[0] = String.class;
pparams[1] = int.class;
pparams[2] = String.class;
Constructor ppcont = ppclass.getConstructor(pparams);
updateProxyInstance.invoke(sJavaBridge, ppcont.newInstance(host, port, null));
return true;
} catch (Exception ex) {
return false;
}
}
/**
* Set Proxy for Android 4.1 - 4.3.
*/
@SuppressWarnings("all")
private static boolean setProxyJB(CustomWebview webview, String host, int port) {
try {
Class wvcClass = Class.forName("android.webkit.WebViewClassic");
Class wvParams[] = new Class[1];
wvParams[0] = Class.forName("android.webkit.WebView");
Method fromWebView = wvcClass.getDeclaredMethod("fromWebView", wvParams);
Object webViewClassic = fromWebView.invoke(null, webview);
Class wv = Class.forName("android.webkit.WebViewClassic");
Field mWebViewCoreField = wv.getDeclaredField("mWebViewCore");
Object mWebViewCoreFieldInstance = getFieldValueSafely(mWebViewCoreField, webViewClassic);
Class wvc = Class.forName("android.webkit.WebViewCore");
Field mBrowserFrameField = wvc.getDeclaredField("mBrowserFrame");
Object mBrowserFrame = getFieldValueSafely(mBrowserFrameField, mWebViewCoreFieldInstance);
Class bf = Class.forName("android.webkit.BrowserFrame");
Field sJavaBridgeField = bf.getDeclaredField("sJavaBridge");
Object sJavaBridge = getFieldValueSafely(sJavaBridgeField, mBrowserFrame);
Class ppclass = Class.forName("android.net.ProxyProperties");
Class pparams[] = new Class[3];
pparams[0] = String.class;
pparams[1] = int.class;
pparams[2] = String.class;
Constructor ppcont = ppclass.getConstructor(pparams);
Class jwcjb = Class.forName("android.webkit.JWebCoreJavaBridge");
Class params[] = new Class[1];
params[0] = Class.forName("android.net.ProxyProperties");
Method updateProxyInstance = jwcjb.getDeclaredMethod("updateProxy", params);
updateProxyInstance.invoke(sJavaBridge, ppcont.newInstance(host, port, null));
} catch (Exception ex) {
return false;
}
return true;
}
// from https://stackoverflow.com/questions/19979578/android-webview-set-proxy-programatically-kitkat
@SuppressLint("NewApi")
@SuppressWarnings("all")
private static void setProxyKKPlus(Context appContext, CustomWebview webView, String host, int port, String applicationClassName) {
System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPort", port + "");
System.setProperty("https.proxyHost", host);
System.setProperty("https.proxyPort", port + "");
try {
Class applictionCls = Class.forName("android.app.Application");
Field loadedApkField = applictionCls.getDeclaredField("mLoadedApk");
loadedApkField.setAccessible(true);
Object loadedApk = loadedApkField.get(appContext);
Class loadedApkCls = Class.forName("android.app.LoadedApk");
Field receiversField = loadedApkCls.getDeclaredField("mReceivers");
receiversField.setAccessible(true);
ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk);
for (Object receiverMap : receivers.values()) {
for (Object rec : ((ArrayMap) receiverMap).keySet()) {
Class clazz = rec.getClass();
if (clazz.getName().contains("ProxyChangeListener")) {
Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
onReceiveMethod.invoke(rec, appContext, intent);
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
private static Object getFieldValueSafely(Field field, Object classInstance) throws IllegalArgumentException, IllegalAccessException {
boolean oldAccessibleValue = field.isAccessible();
field.setAccessible(true);
Object result = field.get(classInstance);
field.setAccessible(oldAccessibleValue);
return result;
}
}

View file

@ -1,7 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<group

Some files were not shown because too many files have changed in this diff Show more