Reformat code

This commit is contained in:
tom79 2019-09-06 17:55:14 +02:00
parent 3ff4c230ae
commit 9c187e19bb
669 changed files with 16675 additions and 14543 deletions

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2017 Thomas Schneider
This file is a part of Fedilab
@ -21,19 +20,25 @@
package="app.fedilab.android">
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"
tools:node="remove" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<application
android:name="app.fedilab.android.activities.MainApplication"
android:allowBackup="false"
@ -49,48 +54,56 @@
<service
android:name="app.fedilab.android.services.LiveNotificationService"
android:exported="false"/>
android:exported="false" />
<service android:name="app.fedilab.android.services.BackupStatusService"
android:exported="false"/>
<service android:name="app.fedilab.android.services.BackupStatusInDataBaseService"
android:exported="false"/>
<service android:name="app.fedilab.android.services.BackupNotificationInDataBaseService"
android:exported="false"/>
<receiver android:name="app.fedilab.android.services.RestartLiveNotificationReceiver"
<service
android:name="app.fedilab.android.services.BackupStatusService"
android:exported="false" />
<service
android:name="app.fedilab.android.services.BackupStatusInDataBaseService"
android:exported="false" />
<service
android:name="app.fedilab.android.services.BackupNotificationInDataBaseService"
android:exported="false" />
<receiver
android:name="app.fedilab.android.services.RestartLiveNotificationReceiver"
android:exported="false">
<intent-filter>
<action android:name="RestartLiveNotificationService" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:name="app.fedilab.android.services.PeertubeUploadReceiver"
<receiver
android:name="app.fedilab.android.services.PeertubeUploadReceiver"
android:exported="false">
<intent-filter>
<action android:name="app.fedilab.android.uploadservice.broadcast.status" />
</intent-filter>
</receiver>
<receiver android:name="app.fedilab.android.services.StopLiveNotificationReceiver"
<receiver
android:name="app.fedilab.android.services.StopLiveNotificationReceiver"
android:exported="false">
<intent-filter>
<action android:name="StopLiveNotificationReceiver" />
</intent-filter>
</receiver>
<service
android:name="app.fedilab.android.services.StreamingHomeTimelineService"
android:exported="false"/>
android:exported="false" />
<service
android:name="app.fedilab.android.services.StreamingFederatedTimelineService"
android:exported="false"/>
android:exported="false" />
<service
android:name="app.fedilab.android.services.StreamingLocalTimelineService"
android:exported="false"/>
android:exported="false" />
<activity
android:name="app.fedilab.android.activities.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode = "adjustResize"
android:windowSoftInputMode="adjustResize"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/AppThemeDark_NoActionBar">
<intent-filter>
@ -105,267 +118,283 @@
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- The app is a good candidate for URL in https://domain.name/@xxxxxx-->
<!-- It should cover every URLs for statuses but some others not related to mastodon matching this scheme -->
<data
android:scheme="https"
android:host="*"
android:pathPrefix="/@"
/>
android:pathPrefix="/@" />
</intent-filter>
<intent-filter
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:host="*" />
<data android:pathPattern=".*\\.fedilab" />
</intent-filter>
</activity>
<activity android:name="app.fedilab.android.activities.MastodonRegisterActivity"
<activity
android:name="app.fedilab.android.activities.MastodonRegisterActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.MastodonShareRegisterActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.MastodonShareRegisterActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
>
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="fedilab.app" android:scheme="https" android:pathPattern="/registration_helper/.*"/>
</intent-filter>
</activity>
<activity android:name="app.fedilab.android.activities.LoginActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="backtomastalab" android:scheme="mastalab" />
</intent-filter>
</activity>
<activity android:name="app.fedilab.android.activities.ShowAccountActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.TootInfoActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.HashTagActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.WebviewConnectActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
<activity android:name="app.fedilab.android.activities.PeertubeActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
<activity android:name="app.fedilab.android.activities.PlaylistsActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
<activity android:name="app.fedilab.android.activities.PhotoEditorActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat"/>
<activity android:name="app.fedilab.android.activities.WebviewActivity"
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="fedilab.app"
android:scheme="https"
android:pathPattern="/registration_helper/.*" />
</intent-filter>
</activity>
<activity
android:name="app.fedilab.android.activities.LoginActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="backtomastalab"
android:scheme="mastalab" />
</intent-filter>
</activity>
<activity
android:name="app.fedilab.android.activities.ShowAccountActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.TootInfoActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.HashTagActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.WebviewConnectActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
<activity android:name="app.fedilab.android.activities.MediaActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name="app.fedilab.android.activities.PeertubeActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name="app.fedilab.android.activities.PlaylistsActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name="app.fedilab.android.activities.PhotoEditorActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat" />
<activity
android:name="app.fedilab.android.activities.WebviewActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name="app.fedilab.android.activities.MediaActivity"
android:label="@string/app_name"
android:theme="@style/Theme.Transparent"
android:configChanges="keyboardHidden|orientation|screenSize"
android:noHistory="true"
/>
<activity android:name="app.fedilab.android.activities.SearchResultActivity"
android:noHistory="true" />
<activity
android:name="app.fedilab.android.activities.SearchResultActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.SearchResultTabActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.ListActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.WhoToFollowActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.ShowConversationActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.OwnerStatusActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.SearchResultTabActivity"
android:launchMode="singleTask" />
<activity
android:name="app.fedilab.android.activities.OwnerNotificationChartsActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.ListActivity"
android:launchMode="singleTask" />
<activity
android:name="app.fedilab.android.activities.OwnerChartsActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.WhoToFollowActivity"
android:launchMode="singleTask" />
<activity
android:name="app.fedilab.android.activities.OwnerNotificationActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.ShowConversationActivity"
android:launchMode="singleTask" />
<activity
android:name="app.fedilab.android.activities.LanguageActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.AboutActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.HideItemActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.SettingsActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.OwnerStatusActivity"
android:launchMode="singleTop" />
<activity
android:name="app.fedilab.android.activities.AdminActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask"
/>
<activity android:name="app.fedilab.android.activities.OwnerNotificationChartsActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.AccountReportActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask"
/>
<activity android:name="app.fedilab.android.activities.OwnerChartsActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.ReorderTimelinesActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask"
/>
<activity android:name="app.fedilab.android.activities.OwnerNotificationActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.OpencollectiveActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask"
/>
<activity android:name="app.fedilab.android.activities.LanguageActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.PartnerShipActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.AboutActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.InstanceActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.HideItemActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.PrivacyActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.SettingsActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
/>
<activity android:name="app.fedilab.android.activities.AdminActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.AccountReportActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.ReorderTimelinesActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.OpencollectiveActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.PartnerShipActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.InstanceActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.PrivacyActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.TootActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.TootActivity"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize"
android:fitsSystemWindows="true"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:theme="@style/AppTheme_NoActionBar_Fedilab"
/>
<activity android:name="app.fedilab.android.activities.EditProfileActivity"
android:theme="@style/AppTheme_NoActionBar_Fedilab" />
<activity
android:name="app.fedilab.android.activities.EditProfileActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.CustomSharingActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.CustomSharingActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.InstanceHealthActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.InstanceHealthActivity"
android:theme="@style/Base.V7.Theme.AppCompat.Dialog"
android:excludeFromRecents="true"/>
<activity android:name="app.fedilab.android.activities.ProxyActivity"
android:excludeFromRecents="true" />
<activity
android:name="app.fedilab.android.activities.ProxyActivity"
android:theme="@style/Base.V7.Theme.AppCompat.Dialog"
android:excludeFromRecents="true"/>
<activity android:name="app.fedilab.android.activities.ManageAccountsInListActivity"
android:excludeFromRecents="true" />
<activity
android:name="app.fedilab.android.activities.ManageAccountsInListActivity"
android:windowSoftInputMode="adjustPan"
android:theme="@style/Base.V7.Theme.AppCompat.Dialog"
android:excludeFromRecents="true"/>
<activity android:name="app.fedilab.android.activities.TagCacheActivity"
android:excludeFromRecents="true" />
<activity
android:name="app.fedilab.android.activities.TagCacheActivity"
android:theme="@style/Base.V7.Theme.AppCompat.Dialog"
android:excludeFromRecents="true"
/>
<activity android:name="app.fedilab.android.activities.PeertubeUploadActivity"
android:excludeFromRecents="true" />
<activity
android:name="app.fedilab.android.activities.PeertubeUploadActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.MutedInstanceActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.MutedInstanceActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.PeertubeEditUploadActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.PeertubeEditUploadActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.GroupActivity"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.GroupActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
android:label="@string/app_name" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileProvider"
@ -373,7 +402,7 @@
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>

View File

@ -22,8 +22,10 @@ import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.view.LayoutInflater;
@ -78,7 +80,7 @@ public class AboutActivity extends BaseActivity implements OnRetrieveRemoteAccou
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -92,10 +94,10 @@ public class AboutActivity extends BaseActivity implements OnRetrieveRemoteAccou
setTheme(R.style.AppThemeDark);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
@ -110,7 +112,7 @@ public class AboutActivity extends BaseActivity implements OnRetrieveRemoteAccou
}
});
toolbar_title.setText(R.string.action_about);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, AboutActivity.this);
}
@ -121,7 +123,8 @@ public class AboutActivity extends BaseActivity implements OnRetrieveRemoteAccou
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;
about_version.setText(getResources().getString(R.string.about_vesrion, version));
} catch (PackageManager.NameNotFoundException ignored) {}
} catch (PackageManager.NameNotFoundException ignored) {
}
ExpandableHeightListView lv_developers = findViewById(R.id.lv_developers);
ExpandableHeightListView lv_designers = findViewById(R.id.lv_designers);
@ -143,11 +146,11 @@ public class AboutActivity extends BaseActivity implements OnRetrieveRemoteAccou
about_code.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://framagit.org/tom79/fedilab"));
startActivity(browserIntent);
}
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://framagit.org/tom79/fedilab"));
startActivity(browserIntent);
}
});
about_thekinrar.setOnClickListener(new View.OnClickListener() {
@ -203,9 +206,9 @@ public class AboutActivity extends BaseActivity implements OnRetrieveRemoteAccou
startActivity(browserIntent);
}
});
if(BuildConfig.DONATIONS){
if (BuildConfig.DONATIONS) {
about_support.setVisibility(View.VISIBLE);
}else{
} else {
about_support.setVisibility(View.GONE);
}
@ -218,14 +221,13 @@ public class AboutActivity extends BaseActivity implements OnRetrieveRemoteAccou
}
});
if(BuildConfig.DONATIONS){
if (BuildConfig.DONATIONS) {
paypal.setVisibility(View.VISIBLE);
}else{
} else {
paypal.setVisibility(View.GONE);
}
TextView about_website = findViewById(R.id.about_website);
about_website.setOnClickListener(new View.OnClickListener() {
@Override
@ -236,9 +238,6 @@ public class AboutActivity extends BaseActivity implements OnRetrieveRemoteAccou
});
setTitle(R.string.action_about);
lv_contributors.setExpanded(true);
lv_developers.setExpanded(true);
@ -254,14 +253,14 @@ public class AboutActivity extends BaseActivity implements OnRetrieveRemoteAccou
accountSearchWebAdapterUxUiDesigners = new AccountSearchDevAdapter(uxuidesigners);
lv_ux.setAdapter(accountSearchWebAdapterUxUiDesigners);
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA ) {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
new RetrieveRemoteDataAsyncTask(getApplicationContext(), "fedilab", "framapiaf.org", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveRemoteDataAsyncTask(getApplicationContext(), "mmarif", "mastodon.social", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveRemoteDataAsyncTask(getApplicationContext(), "kasun", "mastodon.social", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveRemoteDataAsyncTask(getApplicationContext(), "PhotonQyv", "mastodon.xyz", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveRemoteDataAsyncTask(getApplicationContext(), "angrytux", "social.tchncs.de", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveRemoteDataAsyncTask(getApplicationContext(), "guzzisti", "mastodon.social", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
} else {
SpannableString name = new SpannableString("@fedilab@framapiaf.org");
name.setSpan(new UnderlineSpan(), 0, name.length(), 0);
txt_developers.setText(name);
@ -321,13 +320,13 @@ public class AboutActivity extends BaseActivity implements OnRetrieveRemoteAccou
@Override
public void onRetrieveRemoteAccount(Results results) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
if( results == null){
Toasty.error(getApplicationContext(), getString(R.string.toast_error),Toast.LENGTH_LONG).show();
if (results == null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
List<Account> accounts = results.getAccounts();
Account account;
if( accounts != null && accounts.size() > 0){
if (accounts != null && accounts.size() > 0) {
account = accounts.get(0);
account.setFollowing(true);
switch (account.getUsername()) {
@ -348,32 +347,32 @@ public class AboutActivity extends BaseActivity implements OnRetrieveRemoteAccou
accountSearchWebAdapterContributors.notifyDataSetChanged();
break;
}
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(), AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@Override
public void onResume(){
public void onResume() {
super.onResume();
if( developers != null){
for(Account account: developers){
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (developers != null) {
for (Account account : developers) {
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(), AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
if( designers != null){
for(Account account: designers){
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (designers != null) {
for (Account account : designers) {
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(), AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
if( contributors != null){
for(Account account: contributors){
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (contributors != null) {
for (Account account : contributors) {
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(), AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
if( uxuidesigners != null){
for(Account account: uxuidesigners){
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (uxuidesigners != null) {
for (Account account : uxuidesigners) {
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(), AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}
@ -382,32 +381,32 @@ public class AboutActivity extends BaseActivity implements OnRetrieveRemoteAccou
public void onRetrieveRelationship(Relationship relationship, Error error) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, "");
if( error != null){
if (error != null) {
return;
}
for( int i = 0 ; i < developers.size() ; i++){
if( developers.get(i).getId() != null && developers.get(i).getId().equals(relationship.getId())){
for (int i = 0; i < developers.size(); i++) {
if (developers.get(i).getId() != null && developers.get(i).getId().equals(relationship.getId())) {
developers.get(i).setFollowing(relationship.isFollowing() || userId.trim().equals(relationship.getId()));
accountSearchWebAdapterDeveloper.notifyDataSetChanged();
break;
}
}
for( int i = 0 ; i < designers.size() ; i++){
if( designers.get(i).getId() != null && designers.get(i).getId().equals(relationship.getId())){
for (int i = 0; i < designers.size(); i++) {
if (designers.get(i).getId() != null && designers.get(i).getId().equals(relationship.getId())) {
designers.get(i).setFollowing(relationship.isFollowing() || userId.trim().equals(relationship.getId()));
accountSearchWebAdapterDesigner.notifyDataSetChanged();
break;
}
}
for( int i = 0 ; i < contributors.size() ; i++){
if( contributors.get(i).getId() != null && contributors.get(i).getId().equals(relationship.getId())){
for (int i = 0; i < contributors.size(); i++) {
if (contributors.get(i).getId() != null && contributors.get(i).getId().equals(relationship.getId())) {
contributors.get(i).setFollowing(relationship.isFollowing() || userId.trim().equals(relationship.getId()));
accountSearchWebAdapterContributors.notifyDataSetChanged();
break;
}
}
for( int i = 0 ; i < uxuidesigners.size() ; i++){
if( uxuidesigners.get(i).getId() != null && uxuidesigners.get(i).getId().equals(relationship.getId())){
for (int i = 0; i < uxuidesigners.size(); i++) {
if (uxuidesigners.get(i).getId() != null && uxuidesigners.get(i).getId().equals(relationship.getId())) {
uxuidesigners.get(i).setFollowing(relationship.isFollowing() || userId.trim().equals(relationship.getId()));
accountSearchWebAdapterUxUiDesigners.notifyDataSetChanged();
break;

View File

@ -86,7 +86,7 @@ public class AccountReportActivity extends BaseActivity implements OnAdminAction
if (b != null) {
account_id = b.getString("account_id", null);
targeted_account = b.getParcelable("targeted_account");
report = b.getParcelable("report");
report = b.getParcelable("report");
}
if (getSupportActionBar() != null)
@ -136,22 +136,22 @@ public class AccountReportActivity extends BaseActivity implements OnAdminAction
email_user = findViewById(R.id.email_user);
comment = findViewById(R.id.comment);
if( account_id == null && report == null && targeted_account == null){
if (account_id == null && report == null && targeted_account == null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
finish();
}
assign.setVisibility(View.GONE);
status.setVisibility(View.GONE);
if( account_id != null){
if (account_id != null) {
new PostAdminActionAsyncTask(getApplicationContext(), API.adminAction.GET_ONE_ACCOUNT, account_id, null, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return;
}
if( report != null) {
if (report != null) {
targeted_account = report.getTarget_account();
RecyclerView lv_statuses = findViewById(R.id.lv_statuses);
ArrayList<String> contents = new ArrayList<>();
for(Status status: report.getStatuses()){
for (Status status : report.getStatuses()) {
contents.add(status.getContent());
}
lv_statuses.setLayoutManager(new LinearLayoutManager(this));
@ -160,15 +160,15 @@ public class AccountReportActivity extends BaseActivity implements OnAdminAction
Group statuses_group = findViewById(R.id.statuses_group);
statuses_group.setVisibility(View.VISIBLE);
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
new PostAdminActionAsyncTask(getApplicationContext(), API.adminAction.GET_ONE_ACCOUNT, report.getTarget_account().getUsername(), null, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
if( targeted_account != null) {
if (targeted_account != null) {
account_id = targeted_account.getId();
fillReport(targeted_account);
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
account_id = targeted_account.getUsername();
}
}
@ -178,37 +178,37 @@ public class AccountReportActivity extends BaseActivity implements OnAdminAction
@Override
public void onAdminAction(APIResponse apiResponse) {
if( apiResponse.getError() != null){
if( apiResponse.getError().getStatusCode() == 403){
if (apiResponse.getError() != null) {
if (apiResponse.getError().getStatusCode() == 403) {
AlertDialog.Builder builderInner;
builderInner = new AlertDialog.Builder(AccountReportActivity.this, R.style.AdminDialog);
builderInner.setTitle(R.string.reconnect_account);
builderInner.setMessage(R.string.reconnect_account_message);
builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderInner.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(AccountReportActivity.this, LoginActivity.class);
intent.putExtra("admin", true);
startActivity(intent);
}
});
builderInner.show();
}else{
Toasty.error(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
} else {
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
}
return;
}
if( apiResponse.getReports() != null && apiResponse.getReports().size() > 0){
if (apiResponse.getReports() != null && apiResponse.getReports().size() > 0) {
report = apiResponse.getReports().get(0);
fillReport(report.getTarget_account());
} else if( apiResponse.getAccountAdmins() != null && apiResponse.getAccountAdmins().size() > 0) {
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
} else if (apiResponse.getAccountAdmins() != null && apiResponse.getAccountAdmins().size() > 0) {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
account_id = apiResponse.getAccountAdmins().get(0).getUsername();
}
fillReport(apiResponse.getAccountAdmins().get(0));
@ -216,29 +216,29 @@ public class AccountReportActivity extends BaseActivity implements OnAdminAction
}
private void fillReport(AccountAdmin accountAdmin){
private void fillReport(AccountAdmin accountAdmin) {
if( accountAdmin == null){
if (accountAdmin == null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
if(!accountAdmin.isApproved() && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA && (accountAdmin.getDomain() == null || accountAdmin.getDomain().equals("null"))){
if (!accountAdmin.isApproved() && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA && (accountAdmin.getDomain() == null || accountAdmin.getDomain().equals("null"))) {
allow_reject_group.setVisibility(View.VISIBLE);
}
reject.setOnClickListener(view->{
reject.setOnClickListener(view -> {
AdminAction adminAction = new AdminAction();
adminAction.setType(REJECT);
new PostAdminActionAsyncTask(getApplicationContext(), REJECT, account_id, adminAction, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
});
allow.setOnClickListener(view->{
allow.setOnClickListener(view -> {
AdminAction adminAction = new AdminAction();
adminAction.setType(APPROVE);
new PostAdminActionAsyncTask(getApplicationContext(), APPROVE, account_id, adminAction, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
});
warn.setOnClickListener(view->{
warn.setOnClickListener(view -> {
AdminAction adminAction = new AdminAction();
adminAction.setType(NONE);
adminAction.setSend_email_notification(email_user.isChecked());
@ -247,58 +247,58 @@ public class AccountReportActivity extends BaseActivity implements OnAdminAction
});
if( !accountAdmin.isSilenced() ) {
if (!accountAdmin.isSilenced()) {
silence.setText(getString(R.string.silence));
}else{
} else {
silence.setText(getString(R.string.unsilence));
}
silence.setOnClickListener(view->{
if( !accountAdmin.isSilenced() ) {
silence.setOnClickListener(view -> {
if (!accountAdmin.isSilenced()) {
AdminAction adminAction = new AdminAction();
adminAction.setType(SILENCE);
adminAction.setSend_email_notification(email_user.isChecked());
adminAction.setText(comment.getText().toString().trim());
new PostAdminActionAsyncTask(getApplicationContext(), SILENCE, account_id, adminAction, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
} else {
new PostAdminActionAsyncTask(getApplicationContext(), API.adminAction.UNSILENCE, account_id, null, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
if( !accountAdmin.isDisabled() ) {
if (!accountAdmin.isDisabled()) {
disable.setText(getString(R.string.disable));
}else{
} else {
disable.setText(getString(R.string.undisable));
}
disable.setOnClickListener(view->{
if( !accountAdmin.isDisabled()) {
disable.setOnClickListener(view -> {
if (!accountAdmin.isDisabled()) {
AdminAction adminAction = new AdminAction();
adminAction.setType(DISABLE);
adminAction.setSend_email_notification(email_user.isChecked());
adminAction.setText(comment.getText().toString().trim());
new PostAdminActionAsyncTask(getApplicationContext(), DISABLE, account_id, adminAction, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
} else {
new PostAdminActionAsyncTask(getApplicationContext(), API.adminAction.ENABLE, account_id, null, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
if( !accountAdmin.isSuspended() ) {
if (!accountAdmin.isSuspended()) {
suspend.setText(getString(R.string.suspend));
}else{
} else {
suspend.setText(getString(R.string.unsuspend));
}
suspend.setOnClickListener(view->{
if( !accountAdmin.isSuspended() ){
suspend.setOnClickListener(view -> {
if (!accountAdmin.isSuspended()) {
AdminAction adminAction = new AdminAction();
adminAction.setType(SUSPEND);
adminAction.setSend_email_notification(email_user.isChecked());
adminAction.setText(comment.getText().toString().trim());
new PostAdminActionAsyncTask(getApplicationContext(), SUSPEND, account_id, adminAction, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
} else {
new PostAdminActionAsyncTask(getApplicationContext(), API.adminAction.UNSUSPEND, account_id, null, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
if( accountAdmin.getAction() != null) {
if (accountAdmin.getAction() != null) {
String message = null;
switch (accountAdmin.getAction()) {
case SILENCE:
@ -331,7 +331,7 @@ public class AccountReportActivity extends BaseActivity implements OnAdminAction
message = getString(R.string.account_rejected);
break;
}
if( message != null){
if (message != null) {
Toasty.success(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
comment.setText("");
@ -340,35 +340,32 @@ public class AccountReportActivity extends BaseActivity implements OnAdminAction
}
username.setText(String.format("@%s", accountAdmin.getAccount().getAcct()));
email.setText(accountAdmin.getEmail());
if( accountAdmin.getEmail() == null || accountAdmin.getEmail().trim().equals("")){
if (accountAdmin.getEmail() == null || accountAdmin.getEmail().trim().equals("")) {
email.setVisibility(View.GONE);
email_label.setVisibility(View.GONE);
}
if( accountAdmin.getIp() == null || accountAdmin.getIp().trim().equals("")){
if (accountAdmin.getIp() == null || accountAdmin.getIp().trim().equals("")) {
recent_ip.setVisibility(View.GONE);
recent_ip_label.setVisibility(View.GONE);
}
if( accountAdmin.getCreated_at() == null ){
if (accountAdmin.getCreated_at() == null) {
joined.setVisibility(View.GONE);
joined_label.setVisibility(View.GONE);
}
if( accountAdmin.isDisabled()){
if (accountAdmin.isDisabled()) {
login_status.setText(getString(R.string.disabled));
}else if( accountAdmin.isSilenced()){
} else if (accountAdmin.isSilenced()) {
login_status.setText(getString(R.string.silenced));
}else if( accountAdmin.isSuspended()){
} else if (accountAdmin.isSuspended()) {
login_status.setText(getString(R.string.suspended));
}else{
} else {
login_status.setText(getString(R.string.active));
}
if( accountAdmin.getDomain() == null || accountAdmin.getDomain().equals("null")){
if (accountAdmin.getDomain() == null || accountAdmin.getDomain().equals("null")) {
warn.setVisibility(View.VISIBLE);
email_user.setVisibility(View.VISIBLE);
comment_label.setVisibility(View.VISIBLE);
@ -376,7 +373,7 @@ public class AccountReportActivity extends BaseActivity implements OnAdminAction
recent_ip.setText(accountAdmin.getIp());
disable.setVisibility(View.VISIBLE);
suspend.setVisibility(View.VISIBLE);
}else{
} else {
warn.setVisibility(View.GONE);
email_user.setVisibility(View.GONE);
email_user.setChecked(false);
@ -389,7 +386,7 @@ public class AccountReportActivity extends BaseActivity implements OnAdminAction
comment_label.setVisibility(View.GONE);
}
if( accountAdmin.getRole() != null) {
if (accountAdmin.getRole() != null) {
switch (accountAdmin.getRole()) {
case "user":
permissions.setText(getString(R.string.user));
@ -401,7 +398,7 @@ public class AccountReportActivity extends BaseActivity implements OnAdminAction
permissions.setText(getString(R.string.administrator));
break;
}
if( accountAdmin.getRole().equals("admin") || accountAdmin.getRole().equals("moderator")){
if (accountAdmin.getRole().equals("admin") || accountAdmin.getRole().equals("moderator")) {
warn.setVisibility(View.GONE);
suspend.setVisibility(View.GONE);
silence.setVisibility(View.GONE);
@ -411,44 +408,44 @@ public class AccountReportActivity extends BaseActivity implements OnAdminAction
comment.setVisibility(View.GONE);
comment_label.setVisibility(View.GONE);
}
email_status.setText(accountAdmin.isConfirmed()?getString(R.string.confirmed):getString(R.string.unconfirmed));
email_status.setText(accountAdmin.isConfirmed() ? getString(R.string.confirmed) : getString(R.string.unconfirmed));
}
joined.setText(Helper.dateToString(accountAdmin.getCreated_at()));
if( report != null){
if (report != null) {
assign.setVisibility(View.VISIBLE);
status.setVisibility(View.VISIBLE);
if( report.getAssigned_account() == null){
if (report.getAssigned_account() == null) {
assign.setText(getString(R.string.assign_to_me));
}else{
} else {
assign.setText(getString(R.string.unassign));
}
assign.setOnClickListener(view ->{
if( report.getAssigned_account() == null){
assign.setOnClickListener(view -> {
if (report.getAssigned_account() == null) {
new PostAdminActionAsyncTask(getApplicationContext(), API.adminAction.ASSIGN_TO_SELF, report.getId(), null, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
} else {
new PostAdminActionAsyncTask(getApplicationContext(), API.adminAction.UNASSIGN, report.getId(), null, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
if( report.isAction_taken()){
if (report.isAction_taken()) {
status.setText(getString(R.string.mark_unresolved));
}else{
} else {
status.setText(getString(R.string.mark_resolved));
}
status.setOnClickListener(view ->{
if( report.isAction_taken() ){
status.setOnClickListener(view -> {
if (report.isAction_taken()) {
new PostAdminActionAsyncTask(getApplicationContext(), API.adminAction.REOPEN, report.getId(), null, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
} else {
new PostAdminActionAsyncTask(getApplicationContext(), API.adminAction.RESOLVE, report.getId(), null, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
}else{
} else {
assign.setVisibility(View.GONE);
status.setVisibility(View.GONE);
}
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
email_user.setVisibility(View.GONE);
email_user.setChecked(false);
comment.setVisibility(View.INVISIBLE);

View File

@ -25,6 +25,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.PopupMenu;
import androidx.fragment.app.Fragment;
@ -33,7 +34,9 @@ import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.fragment.app.FragmentTransaction;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import app.fedilab.android.R;
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.android.fragments.DisplayAdminAccountsFragment;
@ -49,7 +52,7 @@ import static app.fedilab.android.activities.BaseMainActivity.mPageReferenceMap;
* Admin activity
*/
public class AdminActivity extends BaseActivity {
public class AdminActivity extends BaseActivity {
private boolean unresolved;
@ -65,10 +68,10 @@ public class AdminActivity extends BaseActivity {
setTheme(R.style.AppAdminTheme);
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
@ -82,7 +85,7 @@ public class AdminActivity extends BaseActivity {
finish();
}
});
toolbar_title.setText(String.format(getString(R.string.administration)+ " %s", Helper.getLiveInstance(getApplicationContext())));
toolbar_title.setText(String.format(getString(R.string.administration) + " %s", Helper.getLiveInstance(getApplicationContext())));
}
setContentView(R.layout.activity_admin);
unresolved = local = active = true;
@ -113,7 +116,7 @@ public class AdminActivity extends BaseActivity {
FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
fragTransaction.detach(displayAdminReportsFragment);
Bundle bundle = new Bundle();
bundle.putBoolean("unresolved",unresolved);
bundle.putBoolean("unresolved", unresolved);
displayAdminReportsFragment.setArguments(bundle);
fragTransaction.attach(displayAdminReportsFragment);
fragTransaction.commit();
@ -161,7 +164,7 @@ public class AdminActivity extends BaseActivity {
final MenuItem itemDisabled = menu.findItem(R.id.action_disabled);
final MenuItem itemSilenced = menu.findItem(R.id.action_silenced);
final MenuItem itemSuspended = menu.findItem(R.id.action_suspended);
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
itemSilenced.setVisible(false);
itemPending.setVisible(false);
itemSuspended.setVisible(false);
@ -181,13 +184,13 @@ public class AdminActivity extends BaseActivity {
FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
fragTransaction.detach(displayAdminAccountsFragment);
Bundle bundle = new Bundle();
bundle.putBoolean("local",local);
bundle.putBoolean("remote",remote);
bundle.putBoolean("active",active);
bundle.putBoolean("pending",pending);
bundle.putBoolean("disabled",disabled);
bundle.putBoolean("silenced",silenced);
bundle.putBoolean("suspended",suspended);
bundle.putBoolean("local", local);
bundle.putBoolean("remote", remote);
bundle.putBoolean("active", active);
bundle.putBoolean("pending", pending);
bundle.putBoolean("disabled", disabled);
bundle.putBoolean("silenced", silenced);
bundle.putBoolean("suspended", suspended);
displayAdminAccountsFragment.setArguments(bundle);
fragTransaction.attach(displayAdminAccountsFragment);
fragTransaction.commit();
@ -210,21 +213,21 @@ public class AdminActivity extends BaseActivity {
return false;
}
});
switch (item.getItemId()){
switch (item.getItemId()) {
case R.id.action_local:
if( !local) {
if (!local) {
remote = false;
local = true;
}
break;
case R.id.action_remote:
if( !remote) {
if (!remote) {
remote = true;
local = false;
}
break;
case R.id.action_active:
if( !active) {
if (!active) {
active = true;
pending = false;
disabled = false;
@ -233,7 +236,7 @@ public class AdminActivity extends BaseActivity {
}
break;
case R.id.action_pending:
if( !pending) {
if (!pending) {
pending = true;
active = false;
disabled = false;
@ -242,7 +245,7 @@ public class AdminActivity extends BaseActivity {
}
break;
case R.id.action_disabled:
if( !disabled) {
if (!disabled) {
disabled = true;
active = false;
pending = false;
@ -251,7 +254,7 @@ public class AdminActivity extends BaseActivity {
}
break;
case R.id.action_silenced:
if( !silenced) {
if (!silenced) {
silenced = true;
active = false;
pending = false;
@ -260,7 +263,7 @@ public class AdminActivity extends BaseActivity {
}
break;
case R.id.action_suspended:
if( !suspended) {
if (!suspended) {
suspended = true;
active = false;
pending = false;
@ -286,7 +289,6 @@ public class AdminActivity extends BaseActivity {
});
PagerAdapter mPagerAdapter = new AdminPagerAdapter(getSupportFragmentManager());
admin_viewpager.setAdapter(mPagerAdapter);
admin_viewpager.setOffscreenPageLimit(2);
@ -305,17 +307,17 @@ public class AdminActivity extends BaseActivity {
@Override
public void onTabReselected(TabLayout.Tab tab) {
Fragment fragment = null;
if( admin_viewpager.getAdapter() != null)
if (admin_viewpager.getAdapter() != null)
fragment = (Fragment) admin_viewpager.getAdapter().instantiateItem(admin_viewpager, tab.getPosition());
switch (tab.getPosition()){
switch (tab.getPosition()) {
case 0:
if( fragment != null) {
if (fragment != null) {
displayAdminReportsFragment = ((DisplayAdminReportsFragment) fragment);
displayAdminReportsFragment.scrollToTop();
}
break;
case 1:
if( fragment != null) {
if (fragment != null) {
displayAdminAccountsFragment = ((DisplayAdminAccountsFragment) fragment);
displayAdminAccountsFragment.scrollToTop();
}
@ -337,23 +339,23 @@ public class AdminActivity extends BaseActivity {
@Override
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
switch (position){
switch (position) {
case 0:
displayAdminReportsFragment = new DisplayAdminReportsFragment();
bundle = new Bundle();
bundle.putBoolean("unresolved",unresolved);
bundle.putBoolean("unresolved", unresolved);
displayAdminReportsFragment.setArguments(bundle);
return displayAdminReportsFragment;
case 1:
displayAdminAccountsFragment = new DisplayAdminAccountsFragment();
bundle = new Bundle();
bundle.putBoolean("local",local);
bundle.putBoolean("remote",remote);
bundle.putBoolean("active",active);
bundle.putBoolean("pending",pending);
bundle.putBoolean("disabled",disabled);
bundle.putBoolean("silenced",silenced);
bundle.putBoolean("suspended",suspended);
bundle.putBoolean("local", local);
bundle.putBoolean("remote", remote);
bundle.putBoolean("active", active);
bundle.putBoolean("pending", pending);
bundle.putBoolean("disabled", disabled);
bundle.putBoolean("silenced", silenced);
bundle.putBoolean("suspended", suspended);
displayAdminAccountsFragment.setArguments(bundle);
return displayAdminAccountsFragment;
}

View File

@ -5,8 +5,11 @@ import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import androidx.annotation.NonNull;
import com.google.android.material.snackbar.Snackbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AppCompatActivity;
@ -67,9 +70,9 @@ public class BaseActivity extends AppCompatActivity {
}
@Override
public void onDestroy(){
public void onDestroy() {
super.onDestroy();
if( timer != null){
if (timer != null) {
timer.cancel();
timer = null;
}

View File

@ -22,8 +22,10 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
@ -72,13 +74,14 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
private String bundle_content;
private String bundle_thumbnailurl;
private String bundle_creator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -95,7 +98,7 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
setContentView(R.layout.activity_custom_sharing);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_action_bar, new LinearLayout(getApplicationContext()), false);
@ -105,7 +108,7 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
pp_actionBar = actionBar.getCustomView().findViewById(R.id.pp_actionBar);
title.setText(R.string.settings_title_custom_sharing);
ImageView close_conversation = actionBar.getCustomView().findViewById(R.id.close_conversation);
if( close_conversation != null){
if (close_conversation != null) {
close_conversation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -113,25 +116,25 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
}
});
}
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, CustomSharingActivity.this);
}
}else{
} else {
setTitle(R.string.settings_title_custom_sharing);
}
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
Account account = new AccountDAO(getApplicationContext(),db).getUniqAccount(userId, instance);
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
Bundle b = getIntent().getExtras();
Status status = null;
if(b != null) {
if (b != null) {
status = b.getParcelable("status");
}
if( status == null){
if (status == null) {
finish();
return;
}
@ -142,7 +145,7 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
bundle_source = status.getAccount().getUrl();
String bundle_tags = status.getTagsString();
bundle_content = formatedContent(status.getContent(), status.getEmojis());
if( status.getCard() != null && status.getCard().getImage() != null) {
if (status.getCard() != null && status.getCard().getImage() != null) {
bundle_thumbnailurl = status.getCard().getImage();
} else if (status.getMedia_attachments() != null && status.getMedia_attachments().size() > 0) {
ArrayList<Attachment> mediaAttachments = status.getMedia_attachments();
@ -162,7 +165,7 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
String[] lines = bundle_content.split("\n");
//Remove tags in title
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
lines[0] = Html.fromHtml( lines[0], Html.FROM_HTML_MODE_LEGACY).toString();
lines[0] = Html.fromHtml(lines[0], Html.FROM_HTML_MODE_LEGACY).toString();
else
//noinspection deprecation
lines[0] = Html.fromHtml(lines[0]).toString();
@ -175,7 +178,7 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
set_custom_sharing_title.setText(newTitle);
String newDescription = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
newDescription = Html.fromHtml( bundle_content, Html.FROM_HTML_MODE_LEGACY).toString();
newDescription = Html.fromHtml(bundle_content, Html.FROM_HTML_MODE_LEGACY).toString();
else
//noinspection deprecation
newDescription = Html.fromHtml(bundle_content).toString();
@ -192,8 +195,8 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
CharSequence comma_only = ",";
CharSequence space_only = " ";
CharSequence double_space = " ";
keywords = keywords.replace(comma_only,space_only);
keywords = keywords.replace(double_space,space_only);
keywords = keywords.replace(comma_only, space_only);
keywords = keywords.replace(double_space, space_only);
// Create encodedCustomSharingURL
custom_sharing_url = sharedpreferences.getString(Helper.SET_CUSTOM_SHARING_URL,
"http://example.net/add?token=YOUR_TOKEN&url=${url}&title=${title}" +
@ -218,7 +221,7 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
@Override
public void onCustomSharing(CustomSharingResponse customSharingResponse) {
set_custom_sharing_save.setEnabled(true);
if( customSharingResponse.getError() != null){
if (customSharingResponse.getError() != null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
@ -244,8 +247,8 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
for (String param_name : args) {
paramFound = false;
String param_value = uri.getQueryParameter(param_name);
if(param_value != null)
switch(param_value) {
if (param_value != null)
switch (param_value) {
case "${url}":
paramFound = true;
builder.appendQueryParameter(param_name, bundle_url);
@ -287,14 +290,14 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
}
private String formatedContent(String content, List<Emojis> emojis){
private String formatedContent(String content, List<Emojis> emojis) {
//Avoid null content
if( content == null)
if (content == null)
return "";
if( emojis == null || emojis.size() == 0)
if (emojis == null || emojis.size() == 0)
return content;
for (Emojis emoji : emojis) {
content = content.replaceAll(":"+emoji.getShortcode()+":","<img src='"+emoji.getUrl()+"' width=20 alt='"+emoji.getShortcode()+"'/>");
content = content.replaceAll(":" + emoji.getShortcode() + ":", "<img src='" + emoji.getUrl() + "' width=20 alt='" + emoji.getShortcode() + "'/>");
}
return content;
}

View File

@ -30,12 +30,14 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
@ -86,7 +88,6 @@ import app.fedilab.android.interfaces.OnUpdateCredentialInterface;
public class EditProfileActivity extends BaseActivity implements OnRetrieveAccountInterface, OnUpdateCredentialInterface {
private EditText set_profile_name, set_profile_description;
private ImageView set_profile_picture, set_header_picture;
private Button set_change_profile_picture, set_change_header_picture, set_profile_save;
@ -110,7 +111,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -127,7 +128,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
setContentView(R.layout.activity_edit_profile);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_action_bar, new LinearLayout(getApplicationContext()), false);
@ -137,7 +138,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
pp_actionBar = actionBar.getCustomView().findViewById(R.id.pp_actionBar);
title.setText(R.string.settings_title_profile);
ImageView close_conversation = actionBar.getCustomView().findViewById(R.id.close_conversation);
if( close_conversation != null){
if (close_conversation != null) {
close_conversation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -145,18 +146,17 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
}
});
}
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, EditProfileActivity.this);
}
}else{
} else {
setTitle(R.string.settings_title_profile);
}
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
Account account = new AccountDAO(getApplicationContext(),db).getUniqAccount(userId, instance);
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
@ -174,10 +174,10 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
Version currentVersion = new Version(instanceVersion);
Version minVersion = new Version("2.3");
if(currentVersion.compareTo(minVersion) == 1) {
if (currentVersion.compareTo(minVersion) == 1) {
set_lock_account.setVisibility(View.VISIBLE);
set_sensitive_content.setVisibility(View.VISIBLE);
}else {
} else {
set_lock_account.setVisibility(View.GONE);
set_sensitive_content.setVisibility(View.GONE);
}
@ -207,21 +207,21 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
@Override
public void onRetrieveAccount(Account account, Error error) {
if( error != null ){
Toasty.error(getApplicationContext(),getString(R.string.toast_error), Toast.LENGTH_LONG).show();
if (error != null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
set_profile_name.setText(account.getDisplay_name());
set_profile_name.setSelection(set_profile_name.getText().length());
String content = account.getNote();
if( content != null) {
if (content != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
content = Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY).toString();
else
//noinspection deprecation
content = Html.fromHtml(content).toString();
}else
} else
content = "";
set_profile_description.setText(content);
@ -232,40 +232,44 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
set_profile_description.setEnabled(true);
set_lock_account.setEnabled(true);
set_sensitive_content.setEnabled(true);
if( account.isLocked())
if (account.isLocked())
set_lock_account.setChecked(true);
else
set_lock_account.setChecked(false);
if( account.isSensitive())
if (account.isSensitive())
set_sensitive_content.setChecked(true);
else
set_sensitive_content.setChecked(false);
set_profile_description.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if( s.length() > 160){
String content = s.toString().substring(0,160);
if (s.length() > 160) {
String content = s.toString().substring(0, 160);
set_profile_description.setText(content);
set_profile_description.setSelection(set_profile_description.getText().length());
Toasty.info(getApplicationContext(),getString(R.string.note_no_space),Toast.LENGTH_LONG).show();
Toasty.info(getApplicationContext(), getString(R.string.note_no_space), Toast.LENGTH_LONG).show();
}
}
});
if ( account.getFields() != null && account.getFields().size() > 0){
if (account.getFields() != null && account.getFields().size() > 0) {
HashMap<String, String> fields = account.getFields();
Iterator it = fields.entrySet().iterator();
int i = 1;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
String label = (String)pair.getKey();
String value = (String)pair.getValue();
Map.Entry pair = (Map.Entry) it.next();
String label = (String) pair.getKey();
String value = (String) pair.getValue();
EditText labelView;
EditText valueView;
switch(i){
switch (i) {
case 1:
labelView = findViewById(R.id.cf_key_1);
valueView = findViewById(R.id.cf_val_1);
@ -300,16 +304,20 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
set_profile_name.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if( s.length() > 30){
String content = s.toString().substring(0,30);
if (s.length() > 30) {
String content = s.toString().substring(0, 30);
set_profile_name.setText(content);
set_profile_name.setSelection(set_profile_name.getText().length());
Toasty.info(getApplicationContext(),getString(R.string.username_no_space),Toast.LENGTH_LONG).show();
Toasty.info(getApplicationContext(), getString(R.string.username_no_space), Toast.LENGTH_LONG).show();
}
}
});
@ -334,7 +342,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
pickIntent.setType("image/*");
Intent chooserIntent = Intent.createChooser(getIntent, getString(R.string.toot_select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE_HEADER);
}
});
@ -360,7 +368,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
pickIntent.setType("image/*");
Intent chooserIntent = Intent.createChooser(getIntent, getString(R.string.toot_select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE_PROFILE);
}
});
@ -371,7 +379,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
Glide.with(set_header_picture.getContext())
.load(account.getHeader())
.into(set_header_picture);
if( account.getHeader() == null || account.getHeader().contains("missing.png"))
if (account.getHeader() == null || account.getHeader().contains("missing.png"))
set_header_picture_overlay.setVisibility(View.VISIBLE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
@ -379,21 +387,21 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
set_profile_save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(set_profile_name.getText() != null && !set_profile_name.getText().toString().equals(set_profile_name.getHint()))
if (set_profile_name.getText() != null && !set_profile_name.getText().toString().equals(set_profile_name.getHint()))
profile_username = set_profile_name.getText().toString().trim();
else
profile_username = null;
if(set_profile_description.getText() != null && !set_profile_description.getText().toString().equals(set_profile_description.getHint()))
if (set_profile_description.getText() != null && !set_profile_description.getText().toString().equals(set_profile_description.getHint()))
profile_note = set_profile_description.getText().toString().trim();
else
profile_note = null;
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(EditProfileActivity.this, style);
@ -406,43 +414,43 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
TextView dialog_profile_name = dialogView.findViewById(R.id.dialog_profile_name);
TextView dialog_profile_description = dialogView.findViewById(R.id.dialog_profile_description);
if( profile_username != null)
if (profile_username != null)
dialog_profile_name.setText(profile_username);
if( profile_note != null)
if (profile_note != null)
dialog_profile_description.setText(profile_note);
if( profile_header_bmp != null) {
if (profile_header_bmp != null) {
BitmapDrawable background = new BitmapDrawable(getApplicationContext().getResources(), profile_header_bmp);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
//noinspection deprecation
back_ground_image.setBackgroundDrawable(background);
} else {
back_ground_image.setBackground(background);
}
}else {
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
} else {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
//noinspection deprecation
back_ground_image.setBackgroundDrawable(set_header_picture.getDrawable());
} else {
back_ground_image.setBackground(set_header_picture.getDrawable());
}
}
if( profile_picture_bmp != null) {
if (profile_picture_bmp != null) {
BitmapDrawable background = new BitmapDrawable(getApplicationContext().getResources(), profile_picture_bmp);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
//noinspection deprecation
dialog_profile_picture.setBackgroundDrawable(background);
} else {
dialog_profile_picture.setBackground(background);
}
}else {
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
} else {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
//noinspection deprecation
dialog_profile_picture.setBackgroundDrawable(set_profile_picture.getDrawable());
} else {
dialog_profile_picture.setBackground(set_profile_picture.getDrawable());
}
}
profile_privacy = set_lock_account.isChecked()?API.accountPrivacy.LOCKED:API.accountPrivacy.PUBLIC;
profile_privacy = set_lock_account.isChecked() ? API.accountPrivacy.LOCKED : API.accountPrivacy.PUBLIC;
sensitive = set_sensitive_content.isChecked();
dialogBuilder.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@Override
@ -458,22 +466,22 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
HashMap<String, String> newCustomFields = new HashMap<>();
String key1, key2, key3, key4, val1, val2, val3, val4;
key1 = ((EditText)findViewById(R.id.cf_key_1)).getText().toString();
key2 = ((EditText)findViewById(R.id.cf_key_2)).getText().toString();
key3 = ((EditText)findViewById(R.id.cf_key_3)).getText().toString();
key4 = ((EditText)findViewById(R.id.cf_key_4)).getText().toString();
key1 = ((EditText) findViewById(R.id.cf_key_1)).getText().toString();
key2 = ((EditText) findViewById(R.id.cf_key_2)).getText().toString();
key3 = ((EditText) findViewById(R.id.cf_key_3)).getText().toString();
key4 = ((EditText) findViewById(R.id.cf_key_4)).getText().toString();
val1 = ((EditText)findViewById(R.id.cf_val_1)).getText().toString();
val2 = ((EditText)findViewById(R.id.cf_val_2)).getText().toString();
val3 = ((EditText)findViewById(R.id.cf_val_3)).getText().toString();
val4 = ((EditText)findViewById(R.id.cf_val_4)).getText().toString();
val1 = ((EditText) findViewById(R.id.cf_val_1)).getText().toString();
val2 = ((EditText) findViewById(R.id.cf_val_2)).getText().toString();
val3 = ((EditText) findViewById(R.id.cf_val_3)).getText().toString();
val4 = ((EditText) findViewById(R.id.cf_val_4)).getText().toString();
newCustomFields.put(key1,val1);
newCustomFields.put(key2,val2);
newCustomFields.put(key3,val3);
newCustomFields.put(key4,val4);
newCustomFields.put(key1, val1);
newCustomFields.put(key2, val2);
newCustomFields.put(key3, val3);
newCustomFields.put(key4, val4);
new UpdateCredentialAsyncTask(getApplicationContext(), newCustomFields, profile_username, profile_note, profile_picture, avatarName, header_picture, headerName, profile_privacy, sensitive, EditProfileActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new UpdateCredentialAsyncTask(getApplicationContext(), newCustomFields, profile_username, profile_note, profile_picture, avatarName, header_picture, headerName, profile_privacy, sensitive, EditProfileActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@ -521,7 +529,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_HEADER && resultCode == RESULT_OK) {
if (data == null || data.getData() == null) {
Toasty.error(getApplicationContext(),getString(R.string.toot_select_image_error),Toast.LENGTH_LONG).show();
Toasty.error(getApplicationContext(), getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
return;
}
Uri fileUri = data.getData();
@ -537,9 +545,9 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
e.printStackTrace();
}
header_picture = Helper.compressImage(EditProfileActivity.this, fileUri, Helper.MediaType.MEDIA);
}else if(requestCode == PICK_IMAGE_PROFILE && resultCode == RESULT_OK) {
} else if (requestCode == PICK_IMAGE_PROFILE && resultCode == RESULT_OK) {
if (data == null || data.getData() == null) {
Toasty.error(getApplicationContext(),getString(R.string.toot_select_image_error),Toast.LENGTH_LONG).show();
Toasty.error(getApplicationContext(), getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
return;
}
Uri fileUri = data.getData();
@ -561,7 +569,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
@Override
public void onUpdateCredential(APIResponse apiResponse) {
set_profile_save.setEnabled(true);
if( apiResponse.getError() != null){
if (apiResponse.getError() != null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}

View File

@ -75,7 +75,7 @@ public class GroupActivity extends BaseActivity implements OnRetrieveFeedsInterf
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar);
break;
@ -91,16 +91,16 @@ public class GroupActivity extends BaseActivity implements OnRetrieveFeedsInterf
setContentView(R.layout.activity_group);
Toolbar toolbar = findViewById(R.id.toolbar);
if( theme == THEME_BLACK)
if (theme == THEME_BLACK)
toolbar.setBackgroundColor(ContextCompat.getColor(GroupActivity.this, R.color.black));
setSupportActionBar(toolbar);
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Bundle b = getIntent().getExtras();
if(b != null)
if (b != null)
groupname = b.getString("groupname", null);
if( groupname == null)
if (groupname == null)
finish();
statuses = new ArrayList<>();
max_id = null;
@ -128,23 +128,22 @@ public class GroupActivity extends BaseActivity implements OnRetrieveFeedsInterf
statuses = new ArrayList<>();
firstLoad = true;
flag_loading = true;
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.GNU_GROUP_TIMELINE, groupname,null, max_id, GroupActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.GNU_GROUP_TIMELINE, groupname, null, max_id, GroupActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(this);
lv_status.setLayoutManager(mLayoutManager);
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy)
{
if(dy > 0){
public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
if(!flag_loading ) {
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.GNU_GROUP_TIMELINE, groupname,null, max_id, GroupActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.GNU_GROUP_TIMELINE, groupname, null, max_id, GroupActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
nextElementLoader.setVisibility(View.VISIBLE);
}
@ -154,15 +153,16 @@ public class GroupActivity extends BaseActivity implements OnRetrieveFeedsInterf
}
}
});
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.GNU_GROUP_TIMELINE, groupname,null, max_id, GroupActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.GNU_GROUP_TIMELINE, groupname, null, max_id, GroupActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == THEME_LIGHT)
if (theme == THEME_LIGHT)
Helper.colorizeIconMenu(menu, R.color.black);
return super.onPrepareOptionsMenu(menu);
}
@ -183,24 +183,24 @@ public class GroupActivity extends BaseActivity implements OnRetrieveFeedsInterf
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( apiResponse == null || apiResponse.getError() != null){
if( apiResponse != null) {
if (apiResponse == null || apiResponse.getError() != null) {
if (apiResponse != null) {
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
}else{
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
return;
}
List<Status> statuses = apiResponse.getStatuses();
if( firstLoad && (statuses == null || statuses.size() == 0))
if (firstLoad && (statuses == null || statuses.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
else
textviewNoAction.setVisibility(View.GONE);
if( statuses != null && statuses.size() > 1)
max_id =statuses.get(statuses.size()-1).getId();
if (statuses != null && statuses.size() > 1)
max_id = statuses.get(statuses.size() - 1).getId();
else
max_id = null;
if( statuses != null) {
if (statuses != null) {
this.statuses.addAll(statuses);
statusListAdapter.notifyDataSetChanged();
}

View File

@ -20,11 +20,13 @@ import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -74,7 +76,7 @@ public class HashTagActivity extends BaseActivity implements OnRetrieveFeedsInte
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
break;
@ -90,16 +92,16 @@ public class HashTagActivity extends BaseActivity implements OnRetrieveFeedsInte
setContentView(R.layout.activity_hashtag);
Toolbar toolbar = findViewById(R.id.toolbar);
if( theme == Helper.THEME_BLACK)
if (theme == Helper.THEME_BLACK)
toolbar.setBackgroundColor(ContextCompat.getColor(HashTagActivity.this, R.color.black));
setSupportActionBar(toolbar);
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Bundle b = getIntent().getExtras();
if(b != null)
if (b != null)
tag = b.getString("tag", null);
if( tag == null)
if (tag == null)
finish();
statuses = new ArrayList<>();
max_id = null;
@ -126,23 +128,22 @@ public class HashTagActivity extends BaseActivity implements OnRetrieveFeedsInte
statuses = new ArrayList<>();
firstLoad = true;
flag_loading = true;
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.TAG, tag,null, max_id, HashTagActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.TAG, tag, null, max_id, HashTagActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(this);
lv_status.setLayoutManager(mLayoutManager);
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy)
{
if(dy > 0){
public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
if(!flag_loading ) {
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.TAG, tag,null, max_id, HashTagActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.TAG, tag, null, max_id, HashTagActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
nextElementLoader.setVisibility(View.VISIBLE);
}
@ -152,21 +153,22 @@ public class HashTagActivity extends BaseActivity implements OnRetrieveFeedsInte
}
}
});
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.TAG, tag,null, max_id, HashTagActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.TAG, tag, null, max_id, HashTagActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
SQLiteDatabase db = Sqlite.getInstance(HashTagActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<String> searchInDb = new SearchDAO(HashTagActivity.this, db).getSearchByKeyword(tag.trim());
if( searchInDb == null || searchInDb.size() == 0){
if (searchInDb == null || searchInDb.size() == 0) {
menu.clear();
menu.add(0, 777, Menu.NONE, R.string.pin_add).setIcon(R.drawable.ic_add).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_LIGHT)
if (theme == Helper.THEME_LIGHT)
Helper.colorizeIconMenu(menu, R.color.black);
return super.onPrepareOptionsMenu(menu);
}
@ -195,23 +197,23 @@ public class HashTagActivity extends BaseActivity implements OnRetrieveFeedsInte
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( apiResponse == null || apiResponse.getError() != null){
if( apiResponse != null)
Toasty.error(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
if (apiResponse == null || apiResponse.getError() != null) {
if (apiResponse != null)
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
else
Toasty.error(getApplicationContext(), getString(R.string.toast_error),Toast.LENGTH_LONG).show();
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
List<Status> statuses = apiResponse.getStatuses();
if( firstLoad && (statuses == null || statuses.size() == 0))
if (firstLoad && (statuses == null || statuses.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
else
textviewNoAction.setVisibility(View.GONE);
if( statuses != null && statuses.size() > 1)
max_id =statuses.get(statuses.size()-1).getId();
if (statuses != null && statuses.size() > 1)
max_id = statuses.get(statuses.size() - 1).getId();
else
max_id = null;
if( statuses != null) {
if (statuses != null) {
this.statuses.addAll(statuses);
statusListAdapter.notifyDataSetChanged();
}

View File

@ -27,8 +27,10 @@ import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import app.fedilab.android.R;
import app.fedilab.android.client.Entities.MainMenuItem;
@ -50,7 +52,7 @@ public class HideItemActivity extends BaseActivity {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -64,10 +66,10 @@ public class HideItemActivity extends BaseActivity {
setTheme(R.style.AppThemeDark);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
@ -82,7 +84,7 @@ public class HideItemActivity extends BaseActivity {
}
});
toolbar_title.setText(R.string.hide_menu_items);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, HideItemActivity.this);
}
@ -91,7 +93,7 @@ public class HideItemActivity extends BaseActivity {
SQLiteDatabase db = Sqlite.getInstance(HideItemActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
MainMenuItem mainMenu = new MainMenuDAO(getApplicationContext(), db).getMainMenu();
if( mainMenu == null){
if (mainMenu == null) {
mainMenu = new MainMenuItem();
}
CheckBox nav_news = findViewById(R.id.nav_news);
@ -139,9 +141,9 @@ public class HideItemActivity extends BaseActivity {
mainMenuItem.setNav_howto(nav_how_to.isChecked());
MainMenuItem mainMenuItem1 = new MainMenuDAO(getApplicationContext(), db).getMainMenu();
if( mainMenuItem1 != null){
if (mainMenuItem1 != null) {
new MainMenuDAO(getApplicationContext(), db).updateMenu(mainMenuItem);
}else{
} else {
new MainMenuDAO(getApplicationContext(), db).insertMenu(mainMenuItem);
}
Intent mainActivity = new Intent(HideItemActivity.this, MainActivity.class);

View File

@ -23,9 +23,12 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.MenuItem;
@ -64,7 +67,7 @@ public class InstanceActivity extends BaseActivity implements OnRetrieveInstance
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -78,10 +81,10 @@ public class InstanceActivity extends BaseActivity implements OnRetrieveInstance
setTheme(R.style.AppThemeDark);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
@ -96,13 +99,13 @@ public class InstanceActivity extends BaseActivity implements OnRetrieveInstance
}
});
toolbar_title.setText(R.string.action_about_instance);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, InstanceActivity.this);
}
}
setContentView(R.layout.activity_instance);
Helper.changeDrawableColor(getApplicationContext(), R.drawable.ic_mail_outline,R.color.white);
Helper.changeDrawableColor(getApplicationContext(), R.drawable.ic_mail_outline, R.color.white);
instance_container = findViewById(R.id.instance_container);
loader = findViewById(R.id.loader);
instance_container.setVisibility(View.GONE);
@ -128,12 +131,12 @@ public class InstanceActivity extends BaseActivity implements OnRetrieveInstance
public void onRetrieveInstance(APIResponse apiResponse) {
instance_container.setVisibility(View.VISIBLE);
loader.setVisibility(View.GONE);
if( apiResponse.getError() != null){
if (apiResponse.getError() != null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
final Instance instance = apiResponse.getInstance();
if( instance == null){
if (instance == null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
@ -149,18 +152,18 @@ public class InstanceActivity extends BaseActivity implements OnRetrieveInstance
else
//noinspection deprecation
instance_description.setText(Html.fromHtml(instance.getDescription()));
if( instance.getDescription() == null || instance.getDescription().trim().length() == 0 )
if (instance.getDescription() == null || instance.getDescription().trim().length() == 0)
instance_description.setText(getString(R.string.instance_no_description));
instance_version.setText(instance.getVersion());
instance_uri.setText(instance.getUri());
if( instance.getEmail() == null){
if (instance.getEmail() == null) {
instance_contact.hide();
}
instance_contact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",instance.getEmail(), null));
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", instance.getEmail(), null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "[Mastodon] - " + instance.getUri());
startActivity(Intent.createChooser(emailIntent, getString(R.string.send_email)));
}

View File

@ -15,7 +15,6 @@
package app.fedilab.android.activities;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
@ -30,7 +29,9 @@ import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.view.MenuItem;
@ -77,7 +78,7 @@ public class InstanceHealthActivity extends BaseActivity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -93,10 +94,10 @@ public class InstanceHealthActivity extends BaseActivity {
setContentView(R.layout.activity_instance_social);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
Bundle b = getIntent().getExtras();
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().hide();
instance = Helper.getLiveInstance(getApplicationContext());
if(b != null)
instance = Helper.getLiveInstance(getApplicationContext());
if (b != null)
instance = b.getString("instance", Helper.getLiveInstance(getApplicationContext()));
Button close = findViewById(R.id.close);
@ -143,23 +144,23 @@ public class InstanceHealthActivity extends BaseActivity {
}
private void checkInstance(){
private void checkInstance() {
if( instance == null)
if (instance == null)
return;
new Thread(new Runnable(){
new Thread(new Runnable() {
@Override
public void run() {
try {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("name", instance.trim());
final String response = new HttpsConnection(InstanceHealthActivity.this, instance).get("https://instances.social/api/1.0/instances/show", 30, parameters, Helper.THEKINRAR_SECRET_TOKEN );
if( response != null)
final String response = new HttpsConnection(InstanceHealthActivity.this, instance).get("https://instances.social/api/1.0/instances/show", 30, parameters, Helper.THEKINRAR_SECRET_TOKEN);
if (response != null)
instanceSocial = API.parseInstanceSocialResponse(getApplicationContext(), new JSONObject(response));
runOnUiThread(new Runnable() {
@SuppressLint({"SetTextI18n", "DefaultLocale"})
public void run() {
if( instanceSocial.getThumbnail() != null && !instanceSocial.getThumbnail().equals("null"))
if (instanceSocial.getThumbnail() != null && !instanceSocial.getThumbnail().equals("null"))
Glide.with(getApplicationContext())
.asBitmap()
.load(instanceSocial.getThumbnail())
@ -176,21 +177,21 @@ public class InstanceHealthActivity extends BaseActivity {
BitmapDrawable background = new BitmapDrawable(getResources(), mutableBitmap);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
container.setBackground(background);
}else{
} else {
container.setBackgroundDrawable(background);
}
}
});
name.setText(instanceSocial.getName());
if( instanceSocial.isUp()) {
if (instanceSocial.isUp()) {
up.setText("Is up!");
up.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.green));
}else {
} else {
up.setText("Is down!");
up.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.red));
}
uptime.setText(String.format("Uptime: %.2f %%", (instanceSocial.getUptime()*100)));
if( instanceSocial.getChecked_at() != null)
uptime.setText(String.format("Uptime: %.2f %%", (instanceSocial.getUptime() * 100)));
if (instanceSocial.getChecked_at() != null)
checked_at.setText(String.format("Checked at: %s", Helper.dateToString(instanceSocial.getChecked_at())));
values.setText(String.format("version: %s \n %s users - %s statuses", instanceSocial.getVersion(), Helper.withSuffix(instanceSocial.getUsers()), Helper.withSuffix(instanceSocial.getStatuses())));
instance_container.setVisibility(View.VISIBLE);
@ -198,11 +199,11 @@ public class InstanceHealthActivity extends BaseActivity {
}
});
} catch (Exception ignored) {}
} catch (Exception ignored) {
}
}
}).start();
}
}

View File

@ -22,8 +22,10 @@ import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
@ -73,7 +75,7 @@ public class LanguageActivity extends BaseActivity implements OnRetrieveRemoteAc
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -87,10 +89,10 @@ public class LanguageActivity extends BaseActivity implements OnRetrieveRemoteAc
setTheme(R.style.AppThemeDark);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
@ -105,7 +107,7 @@ public class LanguageActivity extends BaseActivity implements OnRetrieveRemoteAc
}
});
toolbar_title.setText(R.string.languages);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, LanguageActivity.this);
}
@ -113,16 +115,15 @@ public class LanguageActivity extends BaseActivity implements OnRetrieveRemoteAc
setContentView(R.layout.activity_language);
Button about_translation = findViewById(R.id.about_translation);
about_translation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://crowdin.com/project/mastalab"));
startActivity(browserIntent);
}
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://crowdin.com/project/mastalab"));
startActivity(browserIntent);
}
});
ExpandableHeightListView lv_translator_manager = findViewById(R.id.lv_translator_manager);
@ -137,7 +138,6 @@ public class LanguageActivity extends BaseActivity implements OnRetrieveRemoteAc
new RetrieveRemoteDataAsyncTask(getApplicationContext(), "ButterflyOfFire", "mstdn.fr", LanguageActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
String currentLanguage = sharedpreferences.getString(Helper.SET_DEFAULT_LOCALE_NEW, Helper.localeToStringStorage(Locale.getDefault()));
Locale currentLocale = Helper.restoreLocaleFromString(currentLanguage);
final Spinner set_change_locale = findViewById(R.id.set_change_locale);
@ -151,7 +151,7 @@ public class LanguageActivity extends BaseActivity implements OnRetrieveRemoteAc
set_change_locale.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if( count2 > 0 ) {
if (count2 > 0) {
SharedPreferences.Editor editor = sharedpreferences.edit();
switch (position) {
case 0:
@ -179,7 +179,7 @@ public class LanguageActivity extends BaseActivity implements OnRetrieveRemoteAc
editor.commit();
break;
case 6:
editor.putString(Helper.SET_DEFAULT_LOCALE_NEW,"zh-TW");
editor.putString(Helper.SET_DEFAULT_LOCALE_NEW, "zh-TW");
editor.commit();
break;
case 7:
@ -250,6 +250,7 @@ public class LanguageActivity extends BaseActivity implements OnRetrieveRemoteAc
}
count2++;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
@ -274,13 +275,13 @@ public class LanguageActivity extends BaseActivity implements OnRetrieveRemoteAc
@Override
public void onRetrieveRemoteAccount(Results results) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
if( results == null){
Toasty.error(getApplicationContext(), getString(R.string.toast_error),Toast.LENGTH_LONG).show();
if (results == null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
List<Account> accounts = results.getAccounts();
Account account;
if( accounts != null && accounts.size() > 0){
if (accounts != null && accounts.size() > 0) {
account = accounts.get(0);
account.setFollowing(true);
switch (account.getUsername()) {
@ -289,17 +290,17 @@ public class LanguageActivity extends BaseActivity implements OnRetrieveRemoteAc
translatorManager.notifyDataSetChanged();
break;
}
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),LanguageActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(), LanguageActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@Override
public void onResume(){
public void onResume() {
super.onResume();
if( translators != null){
for(Account account: translators){
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),LanguageActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (translators != null) {
for (Account account : translators) {
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(), LanguageActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@ -309,11 +310,11 @@ public class LanguageActivity extends BaseActivity implements OnRetrieveRemoteAc
public void onRetrieveRelationship(Relationship relationship, Error error) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, "");
if( error != null){
if (error != null) {
return;
}
for( int i = 0 ; i < translators.size() ; i++){
if( translators.get(i).getId() != null && translators.get(i).getId().equals(relationship.getId())){
for (int i = 0; i < translators.size(); i++) {
if (translators.get(i).getId() != null && translators.get(i).getId().equals(relationship.getId())) {
translators.get(i).setFollowing(relationship.isFollowing() || userId.trim().equals(relationship.getId()));
translatorManager.notifyDataSetChanged();
break;

View File

@ -20,6 +20,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -28,6 +29,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.text.InputFilter;
import android.view.LayoutInflater;
import android.view.Menu;
@ -79,7 +81,7 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
break;
@ -94,17 +96,17 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
}
setContentView(R.layout.activity_list);
Toolbar toolbar = findViewById(R.id.toolbar);
if( theme == Helper.THEME_BLACK)
if (theme == Helper.THEME_BLACK)
toolbar.setBackgroundColor(ContextCompat.getColor(ListActivity.this, R.color.black));
setSupportActionBar(toolbar);
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
statuses = new ArrayList<>();
RecyclerView lv_status = findViewById(R.id.lv_status);
mainLoader = findViewById(R.id.loader);
mainLoader = findViewById(R.id.loader);
nextElementLoader = findViewById(R.id.loading_next_status);
textviewNoAction = findViewById(R.id.no_action);
textviewNoAction = findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE);
swipeRefreshLayout = findViewById(R.id.swipeContainer);
max_id = null;
@ -124,29 +126,28 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
lv_status.setLayoutManager(mLayoutManager);
Bundle b = getIntent().getExtras();
if(b != null){
if (b != null) {
title = b.getString("title");
listId = b.getString("id");
}else{
Toasty.error(getApplicationContext(),getString(R.string.toast_error_search),Toast.LENGTH_LONG).show();
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(title);
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy)
{
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if(dy > 0){
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
if(!flag_loading ) {
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
new ManageListsAsyncTask(ListActivity.this,listId, max_id ,null, ListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new ManageListsAsyncTask(ListActivity.this, listId, max_id, null, ListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
nextElementLoader.setVisibility(View.VISIBLE);
}
} else {
@ -165,11 +166,11 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
flag_loading = true;
swiped = true;
MainActivity.countNewStatus = 0;
new ManageListsAsyncTask(ListActivity.this,listId, null ,null, ListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new ManageListsAsyncTask(ListActivity.this, listId, null, null, ListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
R.color.mastodonC2,
@ -190,7 +191,7 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
break;
}
new ManageListsAsyncTask(ListActivity.this,listId, null ,null, ListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new ManageListsAsyncTask(ListActivity.this, listId, null, null, ListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@ -218,9 +219,9 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ListActivity.this, style);
@ -233,7 +234,7 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
if( editText.getText() != null && editText.getText().toString().trim().length() > 0 )
if (editText.getText() != null && editText.getText().toString().trim().length() > 0)
new ManageListsAsyncTask(ListActivity.this, ManageListsAsyncTask.action.UPDATE_LIST, null, listId, editText.getText().toString(), editText.getText().toString().trim(), ListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog.dismiss();
}
@ -257,7 +258,7 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
});
if( alertDialog.getWindow() != null )
if (alertDialog.getWindow() != null)
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
return true;
@ -274,14 +275,14 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
nextElementLoader.setVisibility(View.GONE);
//Discards 404 - error which can often happen due to toots which have been deleted
if (apiResponse.getError() != null) {
if ( !apiResponse.getError().getError().startsWith("404 -"))
if (!apiResponse.getError().getError().startsWith("404 -"))
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false);
swiped = false;
flag_loading = false;
return;
}
if( actionType == ManageListsAsyncTask.action.GET_LIST_TIMELINE) {
if (actionType == ManageListsAsyncTask.action.GET_LIST_TIMELINE) {
int previousPosition = this.statuses.size();
List<Status> statuses = apiResponse.getStatuses();
@ -307,7 +308,7 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
}
swipeRefreshLayout.setRefreshing(false);
firstLoad = false;
}else if(actionType == ManageListsAsyncTask.action.UPDATE_LIST) {
} else if (actionType == ManageListsAsyncTask.action.UPDATE_LIST) {
Intent intentUP = new Intent(Helper.RECEIVE_UPDATE_TOPBAR);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intentUP);
}

View File

@ -27,12 +27,15 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import com.google.android.material.textfield.TextInputLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import android.text.Editable;
import android.text.SpannableString;
import android.text.Spanned;
@ -122,11 +125,11 @@ public class LoginActivity extends BaseActivity {
Bundle b = getIntent().getExtras();
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.MASTODON;
admin = false;
if(b != null) {
if (b != null) {
autofilledInstance = b.getString("instance", null);
social = b.getString("social", null);
if( social != null){
switch (social){
if (social != null) {
switch (social) {
case "MASTODON":
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.MASTODON;
break;
@ -141,7 +144,7 @@ public class LoginActivity extends BaseActivity {
admin = b.getBoolean("admin", false);
}
if( getIntent() != null && getIntent().getData() != null && getIntent().getData().toString().contains("mastalab://backtomastalab?code=")){
if (getIntent() != null && getIntent().getData() != null && getIntent().getData().toString().contains("mastalab://backtomastalab?code=")) {
String url = getIntent().getData().toString();
String val[] = url.split("code=");
String code = val[1];
@ -149,10 +152,10 @@ public class LoginActivity extends BaseActivity {
final HashMap<String, String> parameters = new HashMap<>();
parameters.put(Helper.CLIENT_ID, client_id);
parameters.put(Helper.CLIENT_SECRET, client_secret);
parameters.put(Helper.REDIRECT_URI,Helper.REDIRECT_CONTENT_WEB);
parameters.put(Helper.REDIRECT_URI, Helper.REDIRECT_CONTENT_WEB);
parameters.put("grant_type", "authorization_code");
parameters.put("code",code);
new Thread(new Runnable(){
parameters.put("code", code);
new Thread(new Runnable() {
@Override
public void run() {
try {
@ -162,7 +165,7 @@ public class LoginActivity extends BaseActivity {
resobj = new JSONObject(response);
String token = resobj.get("access_token").toString();
String refresh_token = null;
if( resobj.has("refresh_token"))
if (resobj.has("refresh_token"))
refresh_token = resobj.get("refresh_token").toString();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
@ -170,14 +173,19 @@ public class LoginActivity extends BaseActivity {
editor.apply();
//Update the account with the token;
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, instance, socialNetwork).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (JSONException ignored) {ignored.printStackTrace();}
} catch (Exception ignored) {ignored.printStackTrace();}
}}).start();
}else {
} catch (JSONException ignored) {
ignored.printStackTrace();
}
} catch (Exception ignored) {
ignored.printStackTrace();
}
}
}).start();
} else {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -193,7 +201,7 @@ public class LoginActivity extends BaseActivity {
setContentView(R.layout.activity_login);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
@ -208,7 +216,7 @@ public class LoginActivity extends BaseActivity {
}
});
toolbar_title.setText(R.string.add_account);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, LoginActivity.this);
}
@ -220,15 +228,15 @@ public class LoginActivity extends BaseActivity {
}
TextView create_an_account_message = findViewById(R.id.create_an_account);
SpannableString content_create = new SpannableString(getString(R.string.join_mastodon));
SpannableString content_create = new SpannableString(getString(R.string.join_mastodon));
content_create.setSpan(new UnderlineSpan(), 0, content_create.length(), 0);
if( theme == Helper.THEME_DARK)
if (theme == Helper.THEME_DARK)
content_create.setSpan(new ForegroundColorSpan(ContextCompat.getColor(LoginActivity.this, R.color.dark_link_toot)), 0, content_create.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if( theme == Helper.THEME_BLACK)
else if (theme == Helper.THEME_BLACK)
content_create.setSpan(new ForegroundColorSpan(ContextCompat.getColor(LoginActivity.this, R.color.black_link_toot)), 0, content_create.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if( theme == Helper.THEME_LIGHT)
else if (theme == Helper.THEME_LIGHT)
content_create.setSpan(new ForegroundColorSpan(ContextCompat.getColor(LoginActivity.this, R.color.mastodonC4)), 0, content_create.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
create_an_account_message.setText(content_create);
@ -255,7 +263,7 @@ public class LoginActivity extends BaseActivity {
set_instance_type.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {
@Override
public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
switch(position) {
switch (position) {
case 0:
case 1:
case 2:
@ -299,7 +307,7 @@ public class LoginActivity extends BaseActivity {
}
instance = login_instance.getText().toString().trim().toLowerCase();
connect_button.setEnabled(false);
new Thread(new Runnable(){
new Thread(new Runnable() {
@Override
public void run() {
instanceNodeInfo = new API(LoginActivity.this).getNodeInfo(instance);
@ -307,8 +315,8 @@ public class LoginActivity extends BaseActivity {
runOnUiThread(new Runnable() {
public void run() {
connect_button.setEnabled(true);
if(instanceNodeInfo != null && instanceNodeInfo.getName() != null){
switch (instanceNodeInfo.getName()){
if (instanceNodeInfo != null && instanceNodeInfo.getName() != null) {
switch (instanceNodeInfo.getName()) {
case "MASTODON":
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.MASTODON;
break;
@ -322,27 +330,28 @@ public class LoginActivity extends BaseActivity {
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
break;
}
if( instanceNodeInfo.getName().equals("MASTODON") || instanceNodeInfo.getName().equals("PIXELFED")) {
if (instanceNodeInfo.getName().equals("MASTODON") || instanceNodeInfo.getName().equals("PIXELFED")) {
client_id_for_webview = true;
retrievesClientId();
}else {
if( instanceNodeInfo.getName().equals("PEERTUBE")) {
} else {
if (instanceNodeInfo.getName().equals("PEERTUBE")) {
step_login_credential.setVisibility(View.VISIBLE);
step_instance.setVisibility(View.GONE);
instance_chosen.setText(instance);
retrievesClientId();
}else if( instanceNodeInfo.getName().equals("GNU")){
} else if (instanceNodeInfo.getName().equals("GNU")) {
step_login_credential.setVisibility(View.VISIBLE);
step_instance.setVisibility(View.GONE);
instance_chosen.setText(instance);
}
}
}else if(instanceNodeInfo != null && instanceNodeInfo.isConnectionError()){
Toasty.error(getApplicationContext(),getString(R.string.connect_error), Toast.LENGTH_LONG).show();
}else{
Toasty.error(getApplicationContext(),getString(R.string.client_error), Toast.LENGTH_LONG).show();
} else if (instanceNodeInfo != null && instanceNodeInfo.isConnectionError()) {
Toasty.error(getApplicationContext(), getString(R.string.connect_error), Toast.LENGTH_LONG).show();
} else {
Toasty.error(getApplicationContext(), getString(R.string.client_error), Toast.LENGTH_LONG).show();
}
}});
}
});
}
@ -354,7 +363,7 @@ public class LoginActivity extends BaseActivity {
login_instance.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
oldSearch = parent.getItemAtPosition(position).toString().trim();
}
});
@ -377,7 +386,7 @@ public class LoginActivity extends BaseActivity {
parameters.put("count", String.valueOf(1000));
parameters.put("name", String.valueOf(true));
isLoadingInstance = true;
if( oldSearch == null || !oldSearch.equals(s.toString().trim()))
if (oldSearch == null || !oldSearch.equals(s.toString().trim()))
new Thread(new Runnable() {
@Override
public void run() {
@ -393,13 +402,13 @@ public class LoginActivity extends BaseActivity {
if (jsonArray != null) {
int length = 0;
for (int i = 0; i < jsonArray.length(); i++) {
if( !jsonArray.getJSONObject(i).get("name").toString().contains("@"))
if (!jsonArray.getJSONObject(i).get("name").toString().contains("@"))
length++;
}
instances = new String[length];
int j = 0;
for (int i = 0; i < jsonArray.length(); i++) {
if( !jsonArray.getJSONObject(i).get("name").toString().contains("@")) {
if (!jsonArray.getJSONObject(i).get("name").toString().contains("@")) {
instances[j] = jsonArray.getJSONObject(i).get("name").toString();
j++;
}
@ -432,12 +441,12 @@ public class LoginActivity extends BaseActivity {
}
});
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
connectionButton.setEnabled(false);
login_instance.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
connectionButton.setEnabled(false);
TextInputLayout login_instance_layout = findViewById(R.id.login_instance_layout);
if (!hasFocus) {
@ -467,9 +476,9 @@ public class LoginActivity extends BaseActivity {
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this, style);
@ -490,13 +499,13 @@ public class LoginActivity extends BaseActivity {
builder.setIcon(android.R.drawable.ic_dialog_alert).show();
}
});
if( autofilledInstance != null){
if (autofilledInstance != null) {
login_instance.setText(autofilledInstance.trim());
retrievesClientId();
login_uid.requestFocus();
}
if( social != null){
switch (social){
if (social != null) {
switch (social) {
case "MASTODON":
set_instance_type.setSelectedIndex(0);
break;
@ -521,43 +530,44 @@ public class LoginActivity extends BaseActivity {
}
@Override
protected void onResume(){
protected void onResume() {
super.onResume();
if (login_instance != null &&login_instance.getText() != null && login_instance.getText().toString().length() > 0 && client_id_for_webview) {
if (login_instance != null && login_instance.getText() != null && login_instance.getText().toString().length() > 0 && client_id_for_webview) {
connectionButton.setEnabled(false);
client_id_for_webview = false;
retrievesClientId();
}
}
private void retrievesClientId(){
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU){
private void retrievesClientId() {
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
String instanceFromField = login_instance.getText().toString().trim();
String host = instanceFromField;
String host = instanceFromField;
try {
URL url = new URL(instanceFromField);
host = url.getHost();
} catch (MalformedURLException ignored) { }
try {
instance = URLEncoder.encode(host, "utf-8");
} catch (UnsupportedEncodingException e) {
Toasty.error(getApplicationContext(),getString(R.string.client_error), Toast.LENGTH_LONG).show();
} catch (MalformedURLException ignored) {
}
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
try {
instance = URLEncoder.encode(host, "utf-8");
} catch (UnsupportedEncodingException e) {
Toasty.error(getApplicationContext(), getString(R.string.client_error), Toast.LENGTH_LONG).show();
}
if (socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
actionToken = "/api/v1/oauth-clients/local";
else
actionToken = "/api/v1/apps";
final HashMap<String, String> parameters = new HashMap<>();
parameters.put(Helper.CLIENT_NAME, Helper.CLIENT_NAME_VALUE);
parameters.put(Helper.REDIRECT_URIS, client_id_for_webview?Helper.REDIRECT_CONTENT_WEB:Helper.REDIRECT_CONTENT);
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
if( admin ) {
parameters.put(Helper.REDIRECT_URIS, client_id_for_webview ? Helper.REDIRECT_CONTENT_WEB : Helper.REDIRECT_CONTENT);
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
if (admin) {
parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES_ADMIN);
}else{
} else {
parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES);
}
}else {
} else {
parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES_PEERTUBE);
}
/*if(socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED){
@ -568,15 +578,15 @@ public class LoginActivity extends BaseActivity {
}*/
parameters.put(Helper.WEBSITE, Helper.WEBSITE_VALUE);
new Thread(new Runnable(){
new Thread(new Runnable() {
@Override
public void run() {
try {
String response;
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
response = new HttpsConnection(LoginActivity.this, instance).get(Helper.instanceWithProtocol(getApplicationContext(),instance) + actionToken, 30, parameters, null );
if (socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
response = new HttpsConnection(LoginActivity.this, instance).get(Helper.instanceWithProtocol(getApplicationContext(), instance) + actionToken, 30, parameters, null);
else
response = new HttpsConnection(LoginActivity.this, instance).post(Helper.instanceWithProtocol(getApplicationContext(), instance) + actionToken, 30, parameters, null );
response = new HttpsConnection(LoginActivity.this, instance).post(Helper.instanceWithProtocol(getApplicationContext(), instance) + actionToken, 30, parameters, null);
runOnUiThread(new Runnable() {
public void run() {
JSONObject resobj;
@ -585,7 +595,7 @@ public class LoginActivity extends BaseActivity {
client_id = resobj.get(Helper.CLIENT_ID).toString();
client_secret = resobj.get(Helper.CLIENT_SECRET).toString();
String id = null;
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
id = resobj.get(Helper.ID).toString();
manageClient(client_id, client_secret, id);
} catch (JSONException e) {
@ -601,27 +611,27 @@ public class LoginActivity extends BaseActivity {
public void run() {
String message;
if( e.getLocalizedMessage() != null && e.getLocalizedMessage().trim().length() > 0)
if (e.getLocalizedMessage() != null && e.getLocalizedMessage().trim().length() > 0)
message = e.getLocalizedMessage();
else if (e.getMessage() != null && e.getMessage().trim().length() > 0)
message = e.getMessage();
else
message = getString(R.string.client_error);
Toasty.error(getApplicationContext(), message,Toast.LENGTH_LONG).show();
Toasty.error(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
});
}
}
}).start();
}else{
} else {
connectionButton.setEnabled(true);
}
connectionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
connectionButton.setEnabled(false);
if( client_id_for_webview ){
if (client_id_for_webview) {
client_id_for_webview = false;
retrievesClientId();
return;
@ -629,7 +639,7 @@ public class LoginActivity extends BaseActivity {
final HashMap<String, String> parameters = new HashMap<>();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
parameters.put(Helper.CLIENT_ID, sharedpreferences.getString(Helper.CLIENT_ID, null));
parameters.put(Helper.CLIENT_SECRET, sharedpreferences.getString(Helper.CLIENT_SECRET, null));
}
@ -645,15 +655,15 @@ public class LoginActivity extends BaseActivity {
parameters.put("password", login_passwd.getText().toString());
}
String oauthUrl = null;
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
if (socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
parameters.put("scope", " read write follow");
oauthUrl = "/oauth/token";
}else if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
} else if (socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
oauthUrl = "/oauth/token";
}else if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
} else if (socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
parameters.put("scope", "user");
oauthUrl = "/api/v1/users/token";
}else if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
} else if (socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
String instanceFromField = login_instance.getText().toString().trim();
String host;
try {
@ -663,7 +673,7 @@ public class LoginActivity extends BaseActivity {
host = instanceFromField;
}
try {
instance = URLEncoder.encode(host, "utf-8");
instance = URLEncoder.encode(host, "utf-8");
} catch (UnsupportedEncodingException e) {
}
String username = login_uid.getText().toString().trim().toLowerCase();
@ -673,15 +683,15 @@ public class LoginActivity extends BaseActivity {
basicAuth = "Basic " + new String(android.util.Base64.encode(userpass.getBytes(), android.util.Base64.NO_WRAP));
}
String finalOauthUrl = oauthUrl;
new Thread(new Runnable(){
new Thread(new Runnable() {
@Override
public void run() {
try {
String response;
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
response = new HttpsConnection(LoginActivity.this, instance).post(Helper.instanceWithProtocol(getApplicationContext(),instance) + finalOauthUrl, 30, parameters, null );
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
response = new HttpsConnection(LoginActivity.this, instance).post(Helper.instanceWithProtocol(getApplicationContext(), instance) + finalOauthUrl, 30, parameters, null);
else {
response = new HttpsConnection(LoginActivity.this, instance).get(Helper.instanceWithProtocol(getApplicationContext(),instance) + finalOauthUrl, 30, null, basicAuth);
response = new HttpsConnection(LoginActivity.this, instance).get(Helper.instanceWithProtocol(getApplicationContext(), instance) + finalOauthUrl, 30, null, basicAuth);
}
runOnUiThread(new Runnable() {
public void run() {
@ -702,7 +712,7 @@ public class LoginActivity extends BaseActivity {
} catch (JSONException ignored) {
ignored.printStackTrace();
}
}else{
} else {
try {
resobj = new JSONObject(response);
Account account = GNUAPI.parseAccountResponse(LoginActivity.this, resobj);
@ -719,10 +729,10 @@ public class LoginActivity extends BaseActivity {
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin());
editor.putString(Helper.PREF_INSTANCE, instance);
editor.apply();
if( userExists)
if (userExists)
new AccountDAO(LoginActivity.this, db).updateAccount(account);
else {
if( account.getUsername() != null && account.getCreated_at() != null)
if (account.getUsername() != null && account.getCreated_at() != null)
new AccountDAO(LoginActivity.this, db).insertAccount(account);
}
editor.apply();
@ -738,7 +748,7 @@ public class LoginActivity extends BaseActivity {
}
}
});
}catch (final Exception e) {
} catch (final Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
public void run() {
@ -746,13 +756,13 @@ public class LoginActivity extends BaseActivity {
runOnUiThread(new Runnable() {
public void run() {
String message;
if( e.getLocalizedMessage() != null && e.getLocalizedMessage().trim().length() > 0)
if (e.getLocalizedMessage() != null && e.getLocalizedMessage().trim().length() > 0)
message = e.getLocalizedMessage();
else if (e.getMessage() != null && e.getMessage().trim().length() > 0)
message = e.getMessage();
else
message = getString(R.string.client_error);
Toasty.error(getApplicationContext(), message,Toast.LENGTH_LONG).show();
Toasty.error(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
});
}
@ -765,30 +775,29 @@ public class LoginActivity extends BaseActivity {
}
private void manageClient(String client_id, String client_secret, String id) {
private void manageClient(String client_id, String client_secret, String id){
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.CLIENT_ID, client_id);
editor.putString(Helper.CLIENT_SECRET, client_secret);
editor.putString(Helper.ID, id);
editor.apply();
connectionButton.setEnabled(true);
if( client_id_for_webview){
boolean embedded_browser = sharedpreferences.getBoolean(Helper.SET_EMBEDDED_BROWSER, true);
if( embedded_browser) {
Intent i = new Intent(LoginActivity.this, WebviewConnectActivity.class);
i.putExtra("social", socialNetwork);
i.putExtra("instance", instance);
startActivity(i);
}else{
String url = redirectUserToAuthorizeAndLogin(getApplicationContext(), socialNetwork, client_id, instance);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.CLIENT_ID, client_id);
editor.putString(Helper.CLIENT_SECRET, client_secret);
editor.putString(Helper.ID, id);
editor.apply();
connectionButton.setEnabled(true);
if (client_id_for_webview) {
boolean embedded_browser = sharedpreferences.getBoolean(Helper.SET_EMBEDDED_BROWSER, true);
if (embedded_browser) {
Intent i = new Intent(LoginActivity.this, WebviewConnectActivity.class);
i.putExtra("social", socialNetwork);
i.putExtra("instance", instance);
startActivity(i);
} else {
String url = redirectUserToAuthorizeAndLogin(getApplicationContext(), socialNetwork, client_id, instance);
Helper.openBrowser(LoginActivity.this, url);
}
Helper.openBrowser(LoginActivity.this, url);
}
}
}
@Override
@ -814,27 +823,27 @@ public class LoginActivity extends BaseActivity {
if (id == R.id.action_about) {
Intent intent = new Intent(getApplicationContext(), AboutActivity.class);
startActivity(intent);
}else if(id == R.id.action_privacy){
} else if (id == R.id.action_privacy) {
Intent intent = new Intent(getApplicationContext(), PrivacyActivity.class);
startActivity(intent);
}else if(id == R.id.action_proxy){
} else if (id == R.id.action_proxy) {
Intent intent = new Intent(getApplicationContext(), ProxyActivity.class);
startActivity(intent);
}else if(id == R.id.action_custom_tabs){
} else if (id == R.id.action_custom_tabs) {
item.setChecked(!item.isChecked());
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_EMBEDDED_BROWSER, !item.isChecked());
editor.apply();
return false;
}else if(id == R.id.action_provider){
} else if (id == R.id.action_provider) {
item.setChecked(!item.isChecked());
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_SECURITY_PROVIDER, item.isChecked());
editor.apply();
return false;
}else if(id == R.id.action_import_data){
} else if (id == R.id.action_import_data) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (ContextCompat.checkSelfPermission(LoginActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
@ -851,11 +860,11 @@ public class LoginActivity extends BaseActivity {
String[] mimetypes = {"*/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, PICK_IMPORT);
}else {
} else {
intent.setType("*/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_import));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, PICK_IMPORT);
}
}
@ -869,26 +878,26 @@ public class LoginActivity extends BaseActivity {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMPORT && resultCode == RESULT_OK) {
if (data == null || data.getData() == null) {
Toasty.error(getApplicationContext(),getString(R.string.toot_select_file_error),Toast.LENGTH_LONG).show();
Toasty.error(getApplicationContext(), getString(R.string.toot_select_file_error), Toast.LENGTH_LONG).show();
return;
}
String filename = Helper.getFilePathFromURI(getApplicationContext(), data.getData());
Sqlite.importDB(LoginActivity.this, filename);
}else{
Toasty.error(getApplicationContext(),getString(R.string.toot_select_file_error),Toast.LENGTH_LONG).show();
} else {
Toasty.error(getApplicationContext(), getString(R.string.toot_select_file_error), Toast.LENGTH_LONG).show();
}
}
public static String redirectUserToAuthorizeAndLogin(Context context, UpdateAccountInfoAsyncTask.SOCIAL socialNetwork, String clientId, String instance) {
String queryString = Helper.CLIENT_ID + "="+ clientId;
queryString += "&" + Helper.REDIRECT_URI + "="+ Uri.encode(Helper.REDIRECT_CONTENT_WEB);
queryString += "&" + Helper.RESPONSE_TYPE +"=code";
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED ) {
String queryString = Helper.CLIENT_ID + "=" + clientId;
queryString += "&" + Helper.REDIRECT_URI + "=" + Uri.encode(Helper.REDIRECT_CONTENT_WEB);
queryString += "&" + Helper.RESPONSE_TYPE + "=code";
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
if( admin ) {
if (admin) {
queryString += "&" + Helper.SCOPE + "=" + Helper.OAUTH_SCOPES_ADMIN;
}else{
} else {
queryString += "&" + Helper.SCOPE + "=" + Helper.OAUTH_SCOPES;
}
}
@ -896,8 +905,7 @@ public class LoginActivity extends BaseActivity {
}
private void showcaseInstance(final boolean loop){
private void showcaseInstance(final boolean loop) {
BubbleShowCaseBuilder showCaseBuilder = new BubbleShowCaseBuilder(LoginActivity.this)
.title(getString(R.string.instance))
.description(getString(R.string.showcase_instance))
@ -906,35 +914,36 @@ public class LoginActivity extends BaseActivity {
.textColor(Color.WHITE)
.titleTextSize(14)
.descriptionTextSize(12);
if( loop)
showCaseBuilder.showOnce("BUBBLE_SHOW_CASE_INSTANCE_ID");
showCaseBuilder.listener(new BubbleShowCaseListener (){
@Override
public void onTargetClick(BubbleShowCase bubbleShowCase) {
if( loop) {
bubbleShowCase.finishSequence();
}
}
@Override
public void onCloseActionImageClick(BubbleShowCase bubbleShowCase) {
if(loop) {
bubbleShowCase.finishSequence();
}
}
if (loop)
showCaseBuilder.showOnce("BUBBLE_SHOW_CASE_INSTANCE_ID");
showCaseBuilder.listener(new BubbleShowCaseListener() {
@Override
public void onTargetClick(BubbleShowCase bubbleShowCase) {
if (loop) {
bubbleShowCase.finishSequence();
}
}
@Override
public void onBubbleClick(BubbleShowCase bubbleShowCase) {
@Override
public void onCloseActionImageClick(BubbleShowCase bubbleShowCase) {
if (loop) {
bubbleShowCase.finishSequence();
}
}
}
@Override
public void onBubbleClick(BubbleShowCase bubbleShowCase) {
@Override
public void onBackgroundDimClick(BubbleShowCase bubbleShowCase) {
}
}
@Override
public void onBackgroundDimClick(BubbleShowCase bubbleShowCase) {
})
.targetView(login_instance)
.show();
}
})
.targetView(login_instance)
.show();
}
}

View File

@ -19,6 +19,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.StrictMode;
import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;
import androidx.core.content.ContextCompat;
@ -56,7 +57,7 @@ import static app.fedilab.android.helper.Helper.initNetCipher;
*/
@AcraNotification(
resIcon = R.mipmap.ic_launcher, resTitle = R.string.crash_title, resChannelName = R.string.set_crash_reports, resText = R.string.crash_message)
resIcon = R.mipmap.ic_launcher, resTitle = R.string.crash_title, resChannelName = R.string.set_crash_reports, resText = R.string.crash_message)
public class MainApplication extends MultiDexApplication {
@ -79,24 +80,25 @@ public class MainApplication extends MultiDexApplication {
List<Locale> SUPPORTED_LOCALES = new ArrayList<>();
String defaultLocaleString = sharedpreferences.getString(Helper.SET_DEFAULT_LOCALE_NEW, null);
if( defaultLocaleString != null){
if (defaultLocaleString != null) {
Locale defaultLocale;
if( defaultLocaleString.equals("zh-CN"))
if (defaultLocaleString.equals("zh-CN"))
defaultLocale = Locale.SIMPLIFIED_CHINESE;
else if( defaultLocaleString.equals("zh-TW"))
else if (defaultLocaleString.equals("zh-TW"))
defaultLocale = Locale.TRADITIONAL_CHINESE;
else
defaultLocale = new Locale(defaultLocaleString);
SUPPORTED_LOCALES.add(defaultLocale);
}else {
} else {
SUPPORTED_LOCALES.add(Locale.getDefault());
}
LocaleChanger.initialize(getApplicationContext(), SUPPORTED_LOCALES);
}catch (Exception ignored){}
} catch (Exception ignored) {
}
boolean send_crash_reports = sharedpreferences.getBoolean(Helper.SET_SEND_CRASH_REPORTS, false);
if( send_crash_reports) {
if (send_crash_reports) {
CoreConfigurationBuilder ACRABuilder = new CoreConfigurationBuilder(this);
ACRABuilder.setBuildConfigClass(BuildConfig.class).setReportFormat(StringFormat.KEY_VALUE_LIST);
String version = "";
@ -117,19 +119,17 @@ public class MainApplication extends MultiDexApplication {
Toasty.Config.getInstance()
.allowQueue(false)
.apply();
Toasty.Config.getInstance().apply();
}
Toasty.Config.getInstance().apply();
}
@Override
protected void attachBaseContext(Context base)
{
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(MainApplication.this);
}
public static MainApplication getApp(){
public static MainApplication getApp() {
return app;
}
}

View File

@ -17,9 +17,11 @@ package app.fedilab.android.activities;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MenuItem;
@ -45,7 +47,6 @@ import app.fedilab.android.asynctasks.ManageListsAsyncTask;
import app.fedilab.android.interfaces.OnListActionInterface;
/**
* Created by Thomas on 15/12/2017.
* Manage accounts in Lists
@ -68,7 +69,7 @@ public class ManageAccountsInListActivity extends BaseActivity implements OnList
requestWindowFeature(Window.FEATURE_NO_TITLE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(ManageAccountsInListActivity.this, R.color.mastodonC3__));
@ -87,15 +88,15 @@ public class ManageAccountsInListActivity extends BaseActivity implements OnList
}
setContentView(R.layout.activity_manage_accounts_list);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().hide();
Bundle b = getIntent().getExtras();
if(b != null){
if (b != null) {
title = b.getString("title");
listId = b.getString("id");
}else{
Toasty.error(getApplicationContext(),getString(R.string.toast_error),Toast.LENGTH_LONG).show();
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
main_account_container = findViewById(R.id.main_account_container);
@ -113,7 +114,6 @@ public class ManageAccountsInListActivity extends BaseActivity implements OnList
lv_accounts_current.setLayoutManager(mLayoutManager);
list_title.setText(title);
loader.setVisibility(View.VISIBLE);
new ManageListsAsyncTask(ManageAccountsInListActivity.this, ManageListsAsyncTask.action.GET_LIST_ACCOUNT, null, null, listId, null, ManageAccountsInListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -121,20 +121,23 @@ public class ManageAccountsInListActivity extends BaseActivity implements OnList
search_account.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (count > 0) {
search_account.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_close, 0);
}else{
} else {
search_account.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_search, 0);
}
}
@Override
public void afterTextChanged(Editable s) {
if( s != null && s.length() > 0){
new ManageListsAsyncTask(ManageAccountsInListActivity.this, s.toString(), ManageAccountsInListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
if (s != null && s.length() > 0) {
new ManageListsAsyncTask(ManageAccountsInListActivity.this, s.toString(), ManageAccountsInListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
lv_accounts_search.setVisibility(View.GONE);
lv_accounts_current.setVisibility(View.VISIBLE);
}
@ -156,9 +159,9 @@ public class ManageAccountsInListActivity extends BaseActivity implements OnList
});
}
public void addAccount(Account account){
public void addAccount(Account account) {
search_account.setText("");
accounts.add(0,account);
accounts.add(0, account);
accountsInAListAdapter.notifyItemInserted(0);
}
@ -175,16 +178,15 @@ public class ManageAccountsInListActivity extends BaseActivity implements OnList
}
@Override
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
loader.setVisibility(View.GONE);
main_account_container.setVisibility(View.VISIBLE);
if( apiResponse.getError() != null){
Toasty.error(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
if (apiResponse.getError() != null) {
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return;
}
if( actionType == ManageListsAsyncTask.action.GET_LIST_ACCOUNT){
if (actionType == ManageListsAsyncTask.action.GET_LIST_ACCOUNT) {
if (apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0) {
this.accounts.addAll(apiResponse.getAccounts());
accountsInAListAdapter.notifyDataSetChanged();
@ -192,7 +194,7 @@ public class ManageAccountsInListActivity extends BaseActivity implements OnList
lv_accounts_current.setVisibility(View.VISIBLE);
}
}else if( actionType == ManageListsAsyncTask.action.SEARCH_USER){
} else if (actionType == ManageListsAsyncTask.action.SEARCH_USER) {
if (apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0) {
java.util.List<Account> accountsSearch = new ArrayList<>();
accountsSearch.addAll(apiResponse.getAccounts());

View File

@ -40,13 +40,16 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.jaredrummler.materialspinner.MaterialSpinner;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
@ -85,7 +88,7 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -101,7 +104,7 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
setContentView(R.layout.activity_register);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
@ -116,14 +119,13 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
}
});
toolbar_title.setText(R.string.sign_up);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, MastodonRegisterActivity.this);
}
}
MaterialSpinner reg_category = findViewById(R.id.reg_category);
Helper.changeMaterialSpinnerColor(MastodonRegisterActivity.this, reg_category);
String[] categoriesA = {
@ -178,26 +180,26 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
CheckBox agreement = findViewById(R.id.agreement);
error_message = findViewById(R.id.error_message);
signup.setOnClickListener(view->{
signup.setOnClickListener(view -> {
error_message.setVisibility(View.GONE);
if( username.getText().toString().trim().length() == 0 || email.getText().toString().trim().length() == 0 ||
password.getText().toString().trim().length() == 0 || password_confirm.getText().toString().trim().length() == 0 || !agreement.isChecked()){
if (username.getText().toString().trim().length() == 0 || email.getText().toString().trim().length() == 0 ||
password.getText().toString().trim().length() == 0 || password_confirm.getText().toString().trim().length() == 0 || !agreement.isChecked()) {
Toasty.error(getApplicationContext(), getString(R.string.all_field_filled)).show();
return;
}
if(!password.getText().toString().trim().equals(password_confirm.getText().toString().trim())){
if (!password.getText().toString().trim().equals(password_confirm.getText().toString().trim())) {
Toasty.error(getApplicationContext(), getString(R.string.password_error)).show();
return;
}
if(!android.util.Patterns.EMAIL_ADDRESS.matcher(email.getText().toString().trim()).matches()){
if (!android.util.Patterns.EMAIL_ADDRESS.matcher(email.getText().toString().trim()).matches()) {
Toasty.error(getApplicationContext(), getString(R.string.email_error)).show();
return;
}
if(password.getText().toString().trim().length() < 8 ){
if (password.getText().toString().trim().length() < 8) {
Toasty.error(getApplicationContext(), getString(R.string.password_too_short)).show();
return;
}
if(username.getText().toString().matches("[a-zA-Z0-9_]")){
if (username.getText().toString().matches("[a-zA-Z0-9_]")) {
Toasty.error(getApplicationContext(), getString(R.string.username_error)).show();
return;
}
@ -214,13 +216,13 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
}
@Override
protected void onResume(){
protected void onResume() {
super.onResume();
}
@Override
public void onRetrieveInstance(APIResponse apiResponse) {
if( apiResponse.getError() != null ){
if (apiResponse.getError() != null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error_instance_reg), Toast.LENGTH_LONG).show();
return;
}
@ -235,7 +237,7 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
}
public void pickupInstance(String instance){
public void pickupInstance(String instance) {
checkInstance(MastodonRegisterActivity.this, instance);
LinearLayout form_container = findViewById(R.id.form_container);
@ -262,13 +264,13 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
change.setSpan(new UnderlineSpan(), 0, change.length(), 0);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_DARK)
if (theme == Helper.THEME_DARK)
change.setSpan(new ForegroundColorSpan(ContextCompat.getColor(MastodonRegisterActivity.this, R.color.dark_link_toot)), 0, change.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if( theme == Helper.THEME_BLACK)
else if (theme == Helper.THEME_BLACK)
change.setSpan(new ForegroundColorSpan(ContextCompat.getColor(MastodonRegisterActivity.this, R.color.black_link_toot)), 0, change.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if( theme == Helper.THEME_LIGHT)
else if (theme == Helper.THEME_LIGHT)
change.setSpan(new ForegroundColorSpan(ContextCompat.getColor(MastodonRegisterActivity.this, R.color.mastodonC4)), 0, change.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
change_instance.setText(change);
@ -295,35 +297,35 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
String tos = getString(R.string.tos);
String serverrules = getString(R.string.server_rules);
String content_agreement = getString(R.string.agreement_check,
"<a href='https://" + instance + "/about/more' >"+serverrules +"</a>",
"<a href='https://" + instance + "/terms' >"+tos +"</a>"
);
"<a href='https://" + instance + "/about/more' >" + serverrules + "</a>",
"<a href='https://" + instance + "/terms' >" + tos + "</a>"
);
agreement_text.setMovementMethod(LinkMovementMethod.getInstance());
agreement_text.setText(Html.fromHtml(content_agreement));
}
private void checkInstance(Context context, String instance){
private void checkInstance(Context context, String instance) {
new checkRegistration(context, instance).executeOnExecutor(THREAD_POOL_EXECUTOR);
}
@Override
public void onPostStatusAction(APIResponse apiResponse) {
if( apiResponse.getError() != null){
if (apiResponse.getError() != null) {
String errorMessage;
if( apiResponse.getError().getError() != null){
try{
if (apiResponse.getError().getError() != null) {
try {
String[] resp = apiResponse.getError().getError().split(":");
if( resp.length == 2)
if (resp.length == 2)
errorMessage = apiResponse.getError().getError().split(":")[1];
else if( resp.length == 3)
else if (resp.length == 3)
errorMessage = apiResponse.getError().getError().split(":")[2];
else
errorMessage = getString(R.string.toast_error);
}catch (Exception e){
} catch (Exception e) {
errorMessage = getString(R.string.toast_error);
}
}else {
} else {
errorMessage = getString(R.string.toast_error);
}
error_message.setText(errorMessage);
@ -336,16 +338,16 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MastodonRegisterActivity.this, style);
dialogBuilder.setCancelable(false);
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
@ -363,7 +365,7 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
private String instance;
private WeakReference<Context> weakReference;
checkRegistration(Context context, String instance){
checkRegistration(Context context, String instance) {
this.instance = instance;
this.weakReference = new WeakReference<>(context);
}
@ -376,7 +378,7 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
java.util.Scanner s = new java.util.Scanner(connection.getInputStream()).useDelimiter("\\A");
response = s.hasNext() ? s.next() : "";
response = s.hasNext() ? s.next() : "";
}
} catch (IOException e) {
e.printStackTrace();
@ -388,9 +390,9 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
protected void onPostExecute(String result) {
if( result != null && result.contains("invite_request_attributes")){
TextView invitation = ((MastodonRegisterActivity)(weakReference.get())).findViewById(R.id.invitation);
if( invitation != null){
if (result != null && result.contains("invite_request_attributes")) {
TextView invitation = ((MastodonRegisterActivity) (weakReference.get())).findViewById(R.id.invitation);
if (invitation != null) {
invitation.setVisibility(View.VISIBLE);
}
}

View File

@ -80,7 +80,7 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -96,7 +96,7 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
setContentView(R.layout.activity_register);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
@ -111,12 +111,12 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
}
});
toolbar_title.setText(R.string.sign_up);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, MastodonShareRegisterActivity.this);
}
}
if( this.getIntent() == null || this.getIntent().getData() == null){
if (this.getIntent() == null || this.getIntent().getData() == null) {
Intent mainActivity = new Intent(MastodonShareRegisterActivity.this, MastodonRegisterActivity.class);
startActivity(mainActivity);
finish();
@ -125,12 +125,12 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
assert data != null;
String[] splitURL = data.toString().split("registration_helper");
if( splitURL.length < 2 || splitURL[1] == null || splitURL[1].length() == 1){
if (splitURL.length < 2 || splitURL[1] == null || splitURL[1].length() == 1) {
Intent mainActivity = new Intent(MastodonShareRegisterActivity.this, MastodonRegisterActivity.class);
startActivity(mainActivity);
finish();
}
String instance = splitURL[1].replace("/","");
String instance = splitURL[1].replace("/", "");
pickupInstance(instance);
@ -148,26 +148,26 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
CheckBox agreement = findViewById(R.id.agreement);
error_message = findViewById(R.id.error_message);
signup.setOnClickListener(view->{
signup.setOnClickListener(view -> {
error_message.setVisibility(View.GONE);
if( username.getText().toString().trim().length() == 0 || email.getText().toString().trim().length() == 0 ||
password.getText().toString().trim().length() == 0 || password_confirm.getText().toString().trim().length() == 0 || !agreement.isChecked()){
if (username.getText().toString().trim().length() == 0 || email.getText().toString().trim().length() == 0 ||
password.getText().toString().trim().length() == 0 || password_confirm.getText().toString().trim().length() == 0 || !agreement.isChecked()) {
Toasty.error(getApplicationContext(), getString(R.string.all_field_filled)).show();
return;
}
if(!password.getText().toString().trim().equals(password_confirm.getText().toString().trim())){
if (!password.getText().toString().trim().equals(password_confirm.getText().toString().trim())) {
Toasty.error(getApplicationContext(), getString(R.string.password_error)).show();
return;
}
if(!android.util.Patterns.EMAIL_ADDRESS.matcher(email.getText().toString().trim()).matches()){
if (!android.util.Patterns.EMAIL_ADDRESS.matcher(email.getText().toString().trim()).matches()) {
Toasty.error(getApplicationContext(), getString(R.string.email_error)).show();
return;
}
if(password.getText().toString().trim().length() < 8 ){
if (password.getText().toString().trim().length() < 8) {
Toasty.error(getApplicationContext(), getString(R.string.password_too_short)).show();
return;
}
if(username.getText().toString().matches("[a-zA-Z0-9_]")){
if (username.getText().toString().matches("[a-zA-Z0-9_]")) {
Toasty.error(getApplicationContext(), getString(R.string.username_error)).show();
return;
}
@ -184,13 +184,13 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
}
@Override
protected void onResume(){
protected void onResume() {
super.onResume();
}
@Override
public void onRetrieveInstance(APIResponse apiResponse) {
if( apiResponse.getError() != null ){
if (apiResponse.getError() != null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error_instance_reg), Toast.LENGTH_LONG).show();
return;
}
@ -205,7 +205,7 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
}
public void pickupInstance(String instance){
public void pickupInstance(String instance) {
checkInstance(MastodonShareRegisterActivity.this, instance);
@ -223,35 +223,35 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
String tos = getString(R.string.tos);
String serverrules = getString(R.string.server_rules);
String content_agreement = getString(R.string.agreement_check,
"<a href='https://" + instance + "/about/more' >"+serverrules +"</a>",
"<a href='https://" + instance + "/terms' >"+tos +"</a>"
);
"<a href='https://" + instance + "/about/more' >" + serverrules + "</a>",
"<a href='https://" + instance + "/terms' >" + tos + "</a>"
);
agreement_text.setMovementMethod(LinkMovementMethod.getInstance());
agreement_text.setText(Html.fromHtml(content_agreement));
}
private void checkInstance(Context context, String instance){
private void checkInstance(Context context, String instance) {
new checkRegistration(context, instance).executeOnExecutor(THREAD_POOL_EXECUTOR);
}
@Override
public void onPostStatusAction(APIResponse apiResponse) {
if( apiResponse.getError() != null){
if (apiResponse.getError() != null) {
String errorMessage;
if( apiResponse.getError().getError() != null){
try{
if (apiResponse.getError().getError() != null) {
try {
String[] resp = apiResponse.getError().getError().split(":");
if( resp.length == 2)
if (resp.length == 2)
errorMessage = apiResponse.getError().getError().split(":")[1];
else if( resp.length == 3)
else if (resp.length == 3)
errorMessage = apiResponse.getError().getError().split(":")[2];
else
errorMessage = getString(R.string.toast_error);
}catch (Exception e){
} catch (Exception e) {
errorMessage = getString(R.string.toast_error);
}
}else {
} else {
errorMessage = getString(R.string.toast_error);
}
error_message.setText(errorMessage);
@ -264,16 +264,16 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MastodonShareRegisterActivity.this, style);
dialogBuilder.setCancelable(false);
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
@ -291,7 +291,7 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
private String instance;
private WeakReference<Context> weakReference;
checkRegistration(Context context, String instance){
checkRegistration(Context context, String instance) {
this.instance = instance;
this.weakReference = new WeakReference<>(context);
}
@ -304,7 +304,7 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
java.util.Scanner s = new java.util.Scanner(connection.getInputStream()).useDelimiter("\\A");
response = s.hasNext() ? s.next() : "";
response = s.hasNext() ? s.next() : "";
}
} catch (IOException e) {
e.printStackTrace();
@ -316,9 +316,9 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
protected void onPostExecute(String result) {
if( result != null && result.contains("invite_request_attributes")){
TextView invitation = ((MastodonShareRegisterActivity)(weakReference.get())).findViewById(R.id.invitation);
if( invitation != null){
if (result != null && result.contains("invite_request_attributes")) {
TextView invitation = ((MastodonShareRegisterActivity) (weakReference.get())).findViewById(R.id.invitation);
if (invitation != null) {
invitation.setVisibility(View.VISIBLE);
}
}

View File

@ -25,6 +25,7 @@ import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@ -97,7 +98,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
private RelativeLayout loader;
private ArrayList<Attachment> attachments;
private ArrayList<Attachment> attachments;
private PhotoView imageView;
private SimpleExoPlayerView videoView;
private float downX;
@ -126,13 +127,14 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
private ImageButton playView;
private GLAudioVisualizationView visualizerView;
private enum actionSwipe{
private enum actionSwipe {
RIGHT_TO_LEFT,
LEFT_TO_RIGHT,
POP
}
private WebView webview_video;
private ImageButton media_save,media_share, media_close;
private ImageButton media_save, media_share, media_close;
private boolean scheduleHidden, scheduleHiddenDescription;
private SimpleExoPlayer player;
private boolean isSHaring;
@ -148,7 +150,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_BLACK)
if (theme == Helper.THEME_BLACK)
setTheme(R.style.TransparentBlack);
super.onCreate(savedInstanceState);
hideSystemUI();
@ -161,12 +163,12 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
mSwipeBackLayout.setSwipeBackListener(new SwipeBackLayout.OnSwipeBackListener() {
@Override
public void onViewPositionChanged(View mView, float swipeBackFraction, float SWIPE_BACK_FACTOR) {
canSwipe = swipeBackFraction<0.1;
canSwipe = swipeBackFraction < 0.1;
}
@Override
public void onViewSwipeFinished(View mView, boolean isEnd) {
if(!isEnd)
if (!isEnd)
canSwipe = true;
else {
finish();
@ -178,17 +180,17 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
instance = Helper.getLiveInstance(MediaActivity.this);
mSwipeBackLayout.attachToActivity(this);
attachments = getIntent().getParcelableArrayListExtra("mediaArray");
if( getIntent().getExtras() != null)
if (getIntent().getExtras() != null)
mediaPosition = getIntent().getExtras().getInt("position", 1);
if( attachments == null || attachments.size() == 0)
if (attachments == null || attachments.size() == 0)
finish();
RelativeLayout main_container_media = findViewById(R.id.main_container_media);
if( theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
main_container_media.setBackgroundResource(R.color.mastodonC2);
}else if( theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
main_container_media.setBackgroundResource(R.color.black);
}else if( theme == Helper.THEME_DARK){
} else if (theme == Helper.THEME_DARK) {
main_container_media.setBackgroundResource(R.color.mastodonC1_);
}
media_description = findViewById(R.id.media_description);
@ -203,13 +205,13 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
@Override
public void onClick(View view) {
isSHaring = false;
if(attachment.getType().toLowerCase().equals("video") || attachment.getType().toLowerCase().equals("audio") || attachment.getType().toLowerCase().equals("gifv") || attachment.getType().toLowerCase().equals("web")) {
if( attachment != null ) {
if (attachment.getType().toLowerCase().equals("video") || attachment.getType().toLowerCase().equals("audio") || attachment.getType().toLowerCase().equals("gifv") || attachment.getType().toLowerCase().equals("web")) {
if (attachment != null) {
progress.setText("0 %");
progress.setVisibility(View.VISIBLE);
new HttpsConnection(MediaActivity.this, instance).download(attachment.getUrl(), MediaActivity.this);
}
}else {
} else {
if (Build.VERSION.SDK_INT >= 23) {
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
@ -226,13 +228,13 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
@Override
public void onClick(View view) {
isSHaring = true;
if(attachment.getType().toLowerCase().equals("video") || attachment.getType().toLowerCase().equals("audio") ||attachment.getType().toLowerCase().equals("gifv")) {
if( attachment != null ) {
if (attachment.getType().toLowerCase().equals("video") || attachment.getType().toLowerCase().equals("audio") || attachment.getType().toLowerCase().equals("gifv")) {
if (attachment != null) {
progress.setText("0 %");
progress.setVisibility(View.VISIBLE);
new HttpsConnection(MediaActivity.this, instance).download(attachment.getUrl(), MediaActivity.this);
}
}else {
} else {
if (Build.VERSION.SDK_INT >= 23) {
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
@ -257,13 +259,13 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
videoView = findViewById(R.id.media_video);
prev = findViewById(R.id.media_prev);
next = findViewById(R.id.media_next);
if( theme == Helper.THEME_BLACK){
if (theme == Helper.THEME_BLACK) {
changeDrawableColor(getApplicationContext(), prev, R.color.dark_icon);
changeDrawableColor(getApplicationContext(), next, R.color.dark_icon);
}else if(theme == Helper.THEME_LIGHT) {
} else if (theme == Helper.THEME_LIGHT) {
changeDrawableColor(getApplicationContext(), prev, R.color.mastodonC4);
changeDrawableColor(getApplicationContext(), next, R.color.mastodonC4);
}else{
} else {
changeDrawableColor(getApplicationContext(), prev, R.color.white);
changeDrawableColor(getApplicationContext(), next, R.color.white);
}
@ -287,11 +289,11 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
@Override
public void onMatrixChanged(RectF rect) {
imageScale = imageView.getScale();
canSwipe = (imageView.getScale() == 1 );
mSwipeBackLayout.isDisabled(imageView.getScale() != 1 );
canSwipe = (imageView.getScale() == 1);
mSwipeBackLayout.isDisabled(imageView.getScale() != 1);
}
});
if( attachments != null && attachments.size() > 1){
if (attachments != null && attachments.size() > 1) {
prev.setVisibility(View.VISIBLE);
next.setVisibility(View.VISIBLE);
}
@ -313,25 +315,27 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
public void onCompletion(MediaPlayer mp) {
stopPlaying();
}
/**
* Manage touch event
* Allows to swipe from timelines
*
* @param event MotionEvent
* @return boolean
*/
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
Boolean thisControllShown = isControlElementShown;
switch(event.getAction()){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
downX = event.getX();
downY = event.getY();
//Displays navigation left/right buttons
if( attachments != null && attachments.size() > 1){
if(thisControllShown){
if (attachments != null && attachments.size() > 1) {
if (thisControllShown) {
prev.setVisibility(View.GONE);
next.setVisibility(View.GONE);
}else{
} else {
prev.setVisibility(View.VISIBLE);
next.setVisibility(View.VISIBLE);
}
@ -344,19 +348,31 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
float upY = event.getY();
float deltaY = downY - upY;
// swipe horizontal
if( downX > MIN_DISTANCE & (Math.abs(deltaX) > MIN_DISTANCE ) ){
if( !canSwipe || mediaPosition > attachments.size() || mediaPosition < 1 || attachments.size() <= 1)
if (downX > MIN_DISTANCE & (Math.abs(deltaX) > MIN_DISTANCE)) {
if (!canSwipe || mediaPosition > attachments.size() || mediaPosition < 1 || attachments.size() <= 1)
return super.dispatchTouchEvent(event);
if(deltaX < 0) { switchOnSwipe(MediaActivity.actionSwipe.LEFT_TO_RIGHT); return true; }
if(deltaX > 0) { switchOnSwipe(MediaActivity.actionSwipe.RIGHT_TO_LEFT); return true; }
}else if(downY > MIN_DISTANCE & (Math.abs(deltaY) > MIN_DISTANCE ) ){
if(deltaY > 0 && canSwipe) { finish(); return true; }
if(deltaY < 0 && canSwipe) { finish(); return true; }
if (deltaX < 0) {
switchOnSwipe(MediaActivity.actionSwipe.LEFT_TO_RIGHT);
return true;
}
if (deltaX > 0) {
switchOnSwipe(MediaActivity.actionSwipe.RIGHT_TO_LEFT);
return true;
}
} else if (downY > MIN_DISTANCE & (Math.abs(deltaY) > MIN_DISTANCE)) {
if (deltaY > 0 && canSwipe) {
finish();
return true;
}
if (deltaY < 0 && canSwipe) {
finish();
return true;
}
} else {
currentAction = MediaActivity.actionSwipe.POP;
isControlElementShown = !isControlElementShown;
if (thisControllShown) {
if(event.getY() > action_bar_container.getHeight()) {
if (event.getY() > action_bar_container.getHeight()) {
hideSystemUI();
action_bar_container.setVisibility(View.GONE);
if (media_description.getVisibility() == View.VISIBLE) {
@ -389,19 +405,19 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
}
private void switchOnSwipe(actionSwipe action){
private void switchOnSwipe(actionSwipe action) {
loader.setVisibility(View.VISIBLE);
mediaPosition = (action == actionSwipe.LEFT_TO_RIGHT)?mediaPosition-1:mediaPosition+1;
mediaPosition = (action == actionSwipe.LEFT_TO_RIGHT) ? mediaPosition - 1 : mediaPosition + 1;
displayMediaAtPosition(action);
}
private void displayMediaAtPosition(actionSwipe action){
if( mediaPosition > attachments.size() )
private void displayMediaAtPosition(actionSwipe action) {
if (mediaPosition > attachments.size())
mediaPosition = 1;
if( mediaPosition < 1)
if (mediaPosition < 1)
mediaPosition = attachments.size();
currentAction = action;
attachment = attachments.get(mediaPosition-1);
attachment = attachments.get(mediaPosition - 1);
String type = attachment.getType();
String url = attachment.getUrl();
finalUrlDownload = url;
@ -409,26 +425,26 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
imageView.setVisibility(View.GONE);
if( attachment.getDescription() != null && !attachment.getDescription().equals("null")){
if (attachment.getDescription() != null && !attachment.getDescription().equals("null")) {
media_description.setText(attachment.getDescription());
media_description.setVisibility(View.VISIBLE);
}else{
} else {
media_description.setText("");
media_description.setVisibility(View.GONE);
}
preview_url = attachment.getPreview_url();
if( type.equals("unknown")){
if (type.equals("unknown")) {
preview_url = attachment.getRemote_url();
if( preview_url.endsWith(".png") || preview_url.endsWith(".jpg")|| preview_url.endsWith(".jpeg") || preview_url.endsWith(".gif")) {
if (preview_url.endsWith(".png") || preview_url.endsWith(".jpg") || preview_url.endsWith(".jpeg") || preview_url.endsWith(".gif")) {
type = "image";
}else if( preview_url.endsWith(".mp4") || preview_url.endsWith(".mp3") ) {
} else if (preview_url.endsWith(".mp4") || preview_url.endsWith(".mp3")) {
type = "video";
}
url = attachment.getRemote_url();
attachment.setType(type);
}
final String finalUrl = url;
switch (type.toLowerCase()){
switch (type.toLowerCase()) {
case "image":
pbar_inf.setScaleY(1f);
imageView.setVisibility(View.VISIBLE);
@ -436,7 +452,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
pbar_inf.setIndeterminate(true);
loader.setVisibility(View.VISIBLE);
fileVideo = null;
if( !finalUrl.endsWith(".gif")) {
if (!finalUrl.endsWith(".gif")) {
Glide.with(getApplicationContext())
.asBitmap()
.load(preview_url).into(
@ -473,7 +489,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
}
}
);
}else {
} else {
loader.setVisibility(View.GONE);
Glide.with(getApplicationContext())
.load(finalUrl).into(imageView);
@ -497,7 +513,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
ExtractorMediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(uri);
player = ExoPlayerFactory.newSimpleInstance(MediaActivity.this);
if( type.toLowerCase().equals("gifv"))
if (type.toLowerCase().equals("gifv"))
player.setRepeatMode(Player.REPEAT_MODE_ONE);
videoView.setPlayer(player);
loader.setVisibility(View.GONE);
@ -559,9 +575,9 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
.setLayerColors(new int[]{color})
.build();
statusView = findViewById(R.id.status);
timerView = findViewById(R.id.timer);
playView = findViewById(R.id.play);
statusView = findViewById(R.id.status);
timerView = findViewById(R.id.timer);
playView = findViewById(R.id.play);
content_audio.setBackgroundColor(getDarkerColor(color));
content_audio.addView(visualizerView, 0);
playView.setVisibility(View.INVISIBLE);
@ -573,12 +589,12 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
}
public void togglePlaying(View v){
public void togglePlaying(View v) {
HANDLER.postDelayed(new Runnable() {
@Override
public void run() {
if(isPlaying()){
if (isPlaying()) {
stopPlaying();
} else {
startPlaying();
@ -587,7 +603,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
}, 100);
}
private void startPlaying(){
private void startPlaying() {
try {
playeraudio = new MediaPlayer();
@ -617,31 +633,33 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
playerSecondsElapsed = 0;
startTimer();
} catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
}
private void stopPlaying(){
private void stopPlaying() {
statusView.setText("");
statusView.setVisibility(View.INVISIBLE);
playView.setImageResource(R.drawable.aar_ic_play);
visualizerView.release();
if(visualizerHandler != null) {
if (visualizerHandler != null) {
visualizerHandler.stop();
}
if(playeraudio != null){
if (playeraudio != null) {
try {
playeraudio.pause();
} catch (Exception ignored){ }
} catch (Exception ignored) {
}
}
stopTimer();
}
private void startTimer(){
private void startTimer() {
stopTimer();
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@ -662,7 +680,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
});
}
private void stopTimer(){
private void stopTimer() {
if (timer != null) {
timer.cancel();
timer.purge();
@ -670,10 +688,10 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
}
}
private boolean isPlaying(){
private boolean isPlaying() {
try {
return playeraudio != null && playeraudio.isPlaying();
} catch (Exception e){
} catch (Exception e) {
return false;
}
}
@ -682,7 +700,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
@Override
public void onDownloaded(String path, String originUrl, Error error) {
if( path != null) {
if (path != null) {
File response = new File(path);
File dir = getCacheDir();
File from = new File(dir, response.getName());
@ -702,54 +720,57 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
} else {
Helper.manageMoveFileDownload(MediaActivity.this, preview_url, finalUrlDownload, downloadedImage, fileVideo, isSHaring);
}
if( progress != null)
if (progress != null)
progress.setVisibility(View.GONE);
if( loader != null)
if (loader != null)
loader.setVisibility(View.GONE);
}
@Override
public void onPause(){
public void onPause() {
super.onPause();
if( player != null) {
if (player != null) {
player.setPlayWhenReady(false);
}
if( playeraudio != null) {
if (playeraudio != null) {
playeraudio.pause();
}
try {
visualizerView.onPause();
} catch (Exception ignored){ }
} catch (Exception ignored) {
}
}
@Override
public void onDestroy() {
try {
if( visualizerView != null) {
if (visualizerView != null) {
visualizerView.release();
}
if( player != null) {
if (player != null) {
player.release();
}
if( playeraudio != null) {
if (playeraudio != null) {
playeraudio.release();
}
} catch (Exception ignored){ }
} catch (Exception ignored) {
}
super.onDestroy();
}
@Override
public void onResume(){
public void onResume() {
super.onResume();
if( player != null) {
if (player != null) {
player.setPlayWhenReady(true);
}
if( playeraudio != null) {
if (playeraudio != null) {
playeraudio.start();
}
try {
visualizerView.onResume();
} catch (Exception e){ }
} catch (Exception e) {
}
}
@Override
@ -759,16 +780,16 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
}
public void FullScreencall(Boolean shouldFullscreen) {
if(Build.VERSION.SDK_INT < 19) {
if (Build.VERSION.SDK_INT < 19) {
View v = this.getWindow().getDecorView();
if(shouldFullscreen){
if (shouldFullscreen) {
v.setSystemUiVisibility(View.GONE);
}else {
} else {
v.setSystemUiVisibility(View.VISIBLE);
}
} else {
View decorView = getWindow().getDecorView();
if(shouldFullscreen){
if (shouldFullscreen) {
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE
// Set the content to appear under the system bars so that the
@ -780,7 +801,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}else{
} else {
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
@ -791,7 +812,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface,
@Override
public void onUpdateProgress(int progressPercentage) {
progress.setText(String.format("%s%%",String.valueOf(progressPercentage)));
progress.setText(String.format("%s%%", String.valueOf(progressPercentage)));
pbar_inf.setProgress(progressPercentage);
}

View File

@ -97,13 +97,14 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
private boolean swiped;
private RecyclerView lv_domains;
private final int PICK_IMPORT_INSTANCE = 5326;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -116,13 +117,13 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
default:
setTheme(R.style.AppThemeDark);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar_muted_instance, new LinearLayout(getApplicationContext()),false);
View view = inflater.inflate(R.layout.simple_bar_muted_instance, new LinearLayout(getApplicationContext()), false);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
@ -142,9 +143,9 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
int style;
if (theme1 == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme1 == Helper.THEME_BLACK){
} else if (theme1 == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MutedInstanceActivity.this, style);
@ -156,10 +157,10 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
if(add_domain.getText() != null && add_domain.getText().toString().trim().matches("^[\\da-zA-Z.-]+\\.[a-zA-Z.]{2,10}$")){
if (add_domain.getText() != null && add_domain.getText().toString().trim().matches("^[\\da-zA-Z.-]+\\.[a-zA-Z.]{2,10}$")) {
new PostActionAsyncTask(MutedInstanceActivity.this, API.StatusAction.BLOCK_DOMAIN, add_domain.getText().toString().trim(), MutedInstanceActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog.dismiss();
}else{
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_empty_content)).show();
}
}
@ -172,7 +173,7 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setTitle(getString(R.string.block_domain));
if( alertDialog.getWindow() != null )
if (alertDialog.getWindow() != null)
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
break;
@ -181,7 +182,7 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
Helper.exportInstanceBlock(MutedInstanceActivity.this,account.getAcct()+"_"+account.getInstance());
Helper.exportInstanceBlock(MutedInstanceActivity.this, account.getAcct() + "_" + account.getInstance());
break;
case R.id.action_import_instances:
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
@ -200,21 +201,22 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
String[] mimetypes = {"*/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, PICK_IMPORT_INSTANCE);
}else {
} else {
intent.setType("*/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_import));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, PICK_IMPORT_INSTANCE);
}
break;
}
return true;
}});
}
});
popup.show();
});
toolbar_title.setText(R.string.blocked_domains);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, MutedInstanceActivity.this);
}
@ -242,16 +244,16 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
mLayoutManager = new LinearLayoutManager(MutedInstanceActivity.this);
lv_domains.setLayoutManager(mLayoutManager);
lv_domains.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy)
{
if(dy > 0) {
public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
asyncTask = new RetrieveDomainsAsyncTask(MutedInstanceActivity.this, max_id, MutedInstanceActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); nextElementLoader.setVisibility(View.VISIBLE);
asyncTask = new RetrieveDomainsAsyncTask(MutedInstanceActivity.this, max_id, MutedInstanceActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
nextElementLoader.setVisibility(View.VISIBLE);
}
} else {
nextElementLoader.setVisibility(View.GONE);
@ -267,9 +269,10 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
firstLoad = true;
flag_loading = true;
swiped = true;
asyncTask = new RetrieveDomainsAsyncTask(MutedInstanceActivity.this, max_id, MutedInstanceActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
asyncTask = new RetrieveDomainsAsyncTask(MutedInstanceActivity.this, max_id, MutedInstanceActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
R.color.mastodonC2,
@ -298,7 +301,7 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
@Override
public void onDestroy() {
super.onDestroy();
if(asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
asyncTask.cancel(true);
}
@ -315,26 +318,26 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
public void onRetrieveDomains(APIResponse apiResponse) {
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( apiResponse.getError() != null){
Toasty.error(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
if (apiResponse.getError() != null) {
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false);
swiped = false;
flag_loading = false;
return;
}
flag_loading = (apiResponse.getMax_id() == null );
flag_loading = (apiResponse.getMax_id() == null);
List<String> domains = apiResponse.getDomains();
if( !swiped && firstLoad && (domains == null || domains.size() == 0))
if (!swiped && firstLoad && (domains == null || domains.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
else
textviewNoAction.setVisibility(View.GONE);
max_id = apiResponse.getMax_id();
if( swiped ){
if (swiped) {
domainsListAdapter = new DomainsListAdapter(this.domains, textviewNoAction);
lv_domains.setAdapter(domainsListAdapter);
swiped = false;
}
if( domains != null && domains.size() > 0) {
if (domains != null && domains.size() > 0) {
this.domains.addAll(domains);
domainsListAdapter.notifyDataSetChanged();
}
@ -354,25 +357,25 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMPORT_INSTANCE && resultCode == RESULT_OK) {
if (data == null || data.getData() == null) {
Toasty.error(getApplicationContext(),getString(R.string.toot_select_file_error),Toast.LENGTH_LONG).show();
Toasty.error(getApplicationContext(), getString(R.string.toot_select_file_error), Toast.LENGTH_LONG).show();
return;
}
try {
InputStream is = getContentResolver().openInputStream(data.getData());
InputStream is = getContentResolver().openInputStream(data.getData());
HashMap<String, String> resultList = new HashMap<>();
BufferedReader reader = new BufferedReader(new InputStreamReader( is));
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String csvLine;
while ((csvLine = reader.readLine()) != null) {
String[] row = csvLine.split(",");
if( row.length > 1) {
if( !row[0].equals("INSTANCE"))
if (row.length > 1) {
if (!row[0].equals("INSTANCE"))
resultList.put(row[0], row[1]);
}else if(row.length == 1){
if( !row[0].equals("INSTANCE"))
} else if (row.length == 1) {
if (!row[0].equals("INSTANCE"))
resultList.put(row[0], "");
}
}
Helper.importInstanceBlock(MutedInstanceActivity.this,resultList);
Helper.importInstanceBlock(MutedInstanceActivity.this, resultList);
} catch (Exception e) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_SHORT).show();
}
@ -383,14 +386,14 @@ public class MutedInstanceActivity extends BaseActivity implements OnRetrieveDom
@Override
public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) {
if( error != null){
Toasty.error(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();
if (error != null) {
Toasty.error(getApplicationContext(), error.getError(), Toast.LENGTH_LONG).show();
return;
}
Helper.manageMessageStatusCode(MutedInstanceActivity.this, statusCode, statusAction);
this.domains.add(0,userId);
this.domains.add(0, userId);
domainsListAdapter.notifyItemInserted(0);
if( this.domains.size() > 0){
if (this.domains.size() > 0) {
textviewNoAction.setVisibility(View.GONE);
}
}

View File

@ -20,8 +20,10 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
@ -65,7 +67,7 @@ public class OpencollectiveActivity extends BaseActivity implements OnRetrieveRe
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -79,10 +81,10 @@ public class OpencollectiveActivity extends BaseActivity implements OnRetrieveRe
setTheme(R.style.AppThemeDark);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
@ -97,7 +99,7 @@ public class OpencollectiveActivity extends BaseActivity implements OnRetrieveRe
}
});
toolbar_title.setText("Open Collective");
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, OpencollectiveActivity.this);
}
@ -112,11 +114,11 @@ public class OpencollectiveActivity extends BaseActivity implements OnRetrieveRe
Button about_opencollective = findViewById(R.id.about_opencollective);
about_opencollective.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://opencollective.com/mastalab"));
startActivity(browserIntent);
}
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://opencollective.com/mastalab"));
startActivity(browserIntent);
}
});
setTitle("Open Collective");
@ -130,8 +132,8 @@ public class OpencollectiveActivity extends BaseActivity implements OnRetrieveRe
lv_sponsors.setAdapter(sponsorsAdapter);
new RetrieveOpenCollectiveAsyncTask(getApplicationContext(), RetrieveOpenCollectiveAsyncTask.Type.BACKERS, OpencollectiveActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveOpenCollectiveAsyncTask(getApplicationContext(), RetrieveOpenCollectiveAsyncTask.Type.SPONSORS, OpencollectiveActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
new RetrieveOpenCollectiveAsyncTask(getApplicationContext(), RetrieveOpenCollectiveAsyncTask.Type.SPONSORS, OpencollectiveActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
@ -149,16 +151,16 @@ public class OpencollectiveActivity extends BaseActivity implements OnRetrieveRe
@Override
public void onRetrieveRemoteAccount(Results results) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
if( results == null){
Toasty.error(getApplicationContext(), getString(R.string.toast_error),Toast.LENGTH_LONG).show();
if (results == null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
List<Account> accounts = results.getAccounts();
if( accounts != null && accounts.size() > 0){
if( accounts.get(0).getSocial().equals("OPENCOLLECTIVE_BACKER")){
if (accounts != null && accounts.size() > 0) {
if (accounts.get(0).getSocial().equals("OPENCOLLECTIVE_BACKER")) {
bakers.addAll(accounts);
backersAdapter.notifyDataSetChanged();
}else if( accounts.get(0).getSocial().equals("OPENCOLLECTIVE_SPONSOR")){
} else if (accounts.get(0).getSocial().equals("OPENCOLLECTIVE_SPONSOR")) {
sponsors.addAll(accounts);
sponsorsAdapter.notifyDataSetChanged();
}

View File

@ -40,6 +40,7 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.components.IMarker;
@ -99,7 +100,7 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -112,10 +113,10 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
default:
setTheme(R.style.AppThemeDark);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_action_bar, new LinearLayout(getApplicationContext()), false);
@ -129,8 +130,8 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
Account account = new AccountDAO(getApplicationContext(),db).getUniqAccount(userId, instance);
if( account != null) {
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
if (account != null) {
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
}
@ -140,12 +141,12 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
finish();
}
});
if( account != null) {
if (account != null) {
toolbar_title.setText(getString(R.string.owner_charts) + " - " + account.getUsername() + "@" + account.getInstance());
}else{
} else {
toolbar_title.setText(R.string.owner_charts);
}
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, OwnerChartsActivity.this);
}
@ -156,7 +157,7 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
chart = findViewById(R.id.chart);
settings_time_from = findViewById(R.id.settings_time_from);
settings_time_to = findViewById(R.id.settings_time_to);
loader = findViewById(R.id.loader);
loader = findViewById(R.id.loader);
validate = findViewById(R.id.validate);
SQLiteDatabase db = Sqlite.getInstance(OwnerChartsActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
@ -165,11 +166,11 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
int style;
if( theme == Helper.THEME_DARK){
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
}else if( theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
Calendar c = Calendar.getInstance();
@ -226,7 +227,7 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
CustomMarkerView mv = new CustomMarkerView(getApplicationContext(), R.layout.markerview);
chart.setMarkerView(mv);
validate.setOnClickListener(v->{
validate.setOnClickListener(v -> {
loadGraph(dateIni, dateEnd);
});
@ -241,24 +242,27 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
public CustomMarkerView(Context context, int layoutResource) {
super(context, layoutResource);
tvContent = findViewById(R.id.tvContent);
if( theme == Helper.THEME_DARK){
if (theme == Helper.THEME_DARK) {
tvContent.setTextColor(ContextCompat.getColor(context, R.color.dark_text));
}else if( theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
tvContent.setTextColor(ContextCompat.getColor(context, R.color.dark_text));
}else {
} else {
tvContent.setTextColor(ContextCompat.getColor(context, R.color.black));
}
}
@Override
public void refreshContent(Entry e, Highlight highlight) {
Date date = new Date(((long) e.getX()));
tvContent.setText(String.valueOf(Helper.shortDateToString(date) + " - " +(int)e.getY()));
tvContent.setText(String.valueOf(Helper.shortDateToString(date) + " - " + (int) e.getY()));
super.refreshContent(e, highlight);
}
private MPPointF mOffset;
@Override
public MPPointF getOffset() {
if(mOffset == null) {
if (mOffset == null) {
mOffset = new MPPointF(-(getWidth() / 2), -getHeight());
}
return mOffset;
@ -303,7 +307,7 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
}
}
private void loadGraph(Date dateIni, Date dateEnd){
private void loadGraph(Date dateIni, Date dateEnd) {
String dateInitString = Helper.shortDateToString(dateIni);
String dateEndString = Helper.shortDateToString(dateEnd);
@ -329,24 +333,24 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
int i = 0;
Iterator it = charts.getBoosts().entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
boostsEntry.add(new Entry((long)pair.getKey(), (int)pair.getValue()));
Map.Entry pair = (Map.Entry) it.next();
boostsEntry.add(new Entry((long) pair.getKey(), (int) pair.getValue()));
it.remove();
}
List<Entry> repliesEntry = new ArrayList<>();
it = charts.getReplies().entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
repliesEntry.add(new Entry((long)pair.getKey(), (int)pair.getValue()));
Map.Entry pair = (Map.Entry) it.next();
repliesEntry.add(new Entry((long) pair.getKey(), (int) pair.getValue()));
it.remove();
}
List<Entry> statusesEntry = new ArrayList<>();
it = charts.getStatuses().entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
statusesEntry.add(new Entry((long)pair.getKey(), (int)pair.getValue()));
Map.Entry pair = (Map.Entry) it.next();
statusesEntry.add(new Entry((long) pair.getKey(), (int) pair.getValue()));
it.remove();
}
@ -419,7 +423,7 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
description.setEnabled(false);
//Update colors
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
xAxis.setTextColor(Color.BLACK);
dataSetBoosts.setValueTextColor(Color.BLACK);
@ -461,6 +465,7 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
this.mDataFormat = new SimpleDateFormat("dd.MM", Locale.getDefault());
this.mDate = new Date();
}
@Override
public String getFormattedValue(float value) {
return getDateString((long) value);
@ -470,7 +475,7 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
try {
mDate.setTime(timestamp);
return mDataFormat.format(mDate);
} catch(Exception ex) {
} catch (Exception ex) {
return "xx";
}
}

View File

@ -114,7 +114,7 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
break;
@ -136,12 +136,12 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
new IntentFilter(Helper.INTENT_BACKUP_FINISH));
Toolbar toolbar = findViewById(R.id.toolbar);
if( theme == Helper.THEME_BLACK)
if (theme == Helper.THEME_BLACK)
toolbar.setBackgroundColor(ContextCompat.getColor(OwnerNotificationActivity.this, R.color.black));
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ){
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.toot_action_bar, new LinearLayout(getApplicationContext()), false);
@ -157,16 +157,16 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
});
TextView toolbarTitle = actionBar.getCustomView().findViewById(R.id.toolbar_title);
pp_actionBar = actionBar.getCustomView().findViewById(R.id.pp_actionBar);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Helper.colorizeToolbar(actionBar.getCustomView().findViewById(R.id.toolbar), R.color.black, OwnerNotificationActivity.this);
}
toolbarTitle.setText(getString(R.string.owner_cached_notifications));
}
notifications = new ArrayList<>();
RecyclerView lv_notifications = findViewById(R.id.lv_notifications);
mainLoader = findViewById(R.id.loader);
mainLoader = findViewById(R.id.loader);
nextElementLoader = findViewById(R.id.loading_next_status);
textviewNoAction = findViewById(R.id.no_action);
textviewNoAction = findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
max_id = null;
@ -177,28 +177,28 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
notificationsListAdapter = new NotificationsListAdapter(isOnWifi, behaviorWithAttachments,this.notifications);
notificationsListAdapter = new NotificationsListAdapter(isOnWifi, behaviorWithAttachments, this.notifications);
lv_notifications.setAdapter(notificationsListAdapter);
mLayoutManager = new LinearLayoutManager(OwnerNotificationActivity.this);
lv_notifications.setLayoutManager(mLayoutManager);
if( theme == Helper.THEME_DARK){
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
}else if( theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
SQLiteDatabase db = Sqlite.getInstance(OwnerNotificationActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account account = new AccountDAO(OwnerNotificationActivity.this,db).getUniqAccount(userId, instance);
Account account = new AccountDAO(OwnerNotificationActivity.this, db).getUniqAccount(userId, instance);
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
swipeRefreshLayout = findViewById(R.id.swipeContainer);
new RetrieveNotificationsCacheAsyncTask(OwnerNotificationActivity.this, filterNotifications, null, OwnerNotificationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
R.color.mastodonC2,
@ -230,14 +230,13 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
});
lv_notifications.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy)
{
public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy) {
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if(dy > 0){
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
if(!flag_loading ) {
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
new RetrieveNotificationsCacheAsyncTask(OwnerNotificationActivity.this, filterNotifications, max_id, OwnerNotificationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
nextElementLoader.setVisibility(View.VISIBLE);
@ -257,7 +256,7 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
getMenuInflater().inflate(R.menu.option_owner_cache, menu);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_LIGHT)
if (theme == Helper.THEME_LIGHT)
Helper.colorizeIconMenu(menu, R.color.black);
return true;
}
@ -287,6 +286,7 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
}
};
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -303,9 +303,9 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(OwnerNotificationActivity.this, style);
@ -321,9 +321,9 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
}
});
dialogBuilder.create().show();
if( statistics == null) {
new RetrieveNotificationStatsAsyncTask(getApplicationContext(), OwnerNotificationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
if (statistics == null) {
new RetrieveNotificationStatsAsyncTask(getApplicationContext(), OwnerNotificationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
displayStats();
}
return true;
@ -332,9 +332,9 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
dialogBuilder = new AlertDialog.Builder(OwnerNotificationActivity.this, style);
@ -344,11 +344,11 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
SQLiteDatabase db = Sqlite.getInstance(OwnerNotificationActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
if( dateIni == null)
if (dateIni == null)
dateIni = new NotificationCacheDAO(OwnerNotificationActivity.this, db).getSmallerDate();
if( dateEnd == null)
if (dateEnd == null)
dateEnd = new NotificationCacheDAO(OwnerNotificationActivity.this, db).getGreaterDate();
if( dateIni == null || dateEnd == null)
if (dateIni == null || dateEnd == null)
return true;
String dateInitString = Helper.shortDateToString(dateIni);
String dateEndString = Helper.shortDateToString(dateEnd);
@ -374,7 +374,6 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
filter_poll.setChecked(filterNotifications.isPoll());
Calendar c = Calendar.getInstance();
c.setTime(dateIni);
int yearIni = c.get(Calendar.YEAR);
@ -440,7 +439,6 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
}
private BroadcastReceiver backupFinishedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@ -459,8 +457,8 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
.unregisterReceiver(backupFinishedReceiver);
}
private void displayStats(){
if( statsDialogView != null){
private void displayStats() {
if (statsDialogView != null) {
ScrollView stats_container = statsDialogView.findViewById(R.id.stats_container);
RelativeLayout loader = statsDialogView.findViewById(R.id.loader);
@ -478,7 +476,7 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
ImageButton charts = statsDialogView.findViewById(R.id.charts);
charts.setOnClickListener(w ->{
charts.setOnClickListener(w -> {
Intent intent = new Intent(OwnerNotificationActivity.this, OwnerNotificationChartsActivity.class);
startActivity(intent);
});
@ -500,8 +498,8 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
stats_container.setVisibility(View.VISIBLE);
loader.setVisibility(View.GONE);
}else{
Toasty.error(getApplicationContext(),getString(R.string.toast_error),Toast.LENGTH_SHORT).show();
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_SHORT).show();
}
}
@ -510,8 +508,8 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
//Discards 404 - error which can often happen due to toots which have been deleted
if( apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 ){
Toasty.error(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
if (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404) {
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false);
swiped = false;
flag_loading = false;
@ -520,13 +518,13 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
int previousPosition = this.notifications.size();
List<Notification> notifications = apiResponse.getNotifications();
max_id = apiResponse.getMax_id();
flag_loading = (max_id == null );
if( !swiped && firstLoad && (notifications == null || notifications.size() == 0))
flag_loading = (max_id == null);
if (!swiped && firstLoad && (notifications == null || notifications.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
else
textviewNoAction.setVisibility(View.GONE);
if( swiped ){
if (swiped) {
if (previousPosition > 0) {
for (int i = 0; i < previousPosition; i++) {
this.notifications.remove(0);
@ -535,11 +533,11 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
}
swiped = false;
}
if( notifications != null && notifications.size() > 0) {
if (notifications != null && notifications.size() > 0) {
this.notifications.addAll(notifications);
notificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size());
}else {
if( textviewNoAction.getVisibility() != View.VISIBLE && firstLoad) {
} else {
if (textviewNoAction.getVisibility() != View.VISIBLE && firstLoad) {
RelativeLayout no_result = findViewById(R.id.no_result);
no_result.setVisibility(View.VISIBLE);
}

View File

@ -101,7 +101,7 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -116,12 +116,12 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
}
Bundle b = getIntent().getExtras();
status_id = null;
if(b != null)
if (b != null)
status_id = b.getString("status_id");
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_action_bar, new LinearLayout(getApplicationContext()), false);
@ -135,8 +135,8 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
Account account = new AccountDAO(getApplicationContext(),db).getUniqAccount(userId, instance);
if( account != null) {
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
if (account != null) {
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
}
@ -146,12 +146,12 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
finish();
}
});
if( account != null) {
if (account != null) {
toolbar_title.setText(getString(R.string.owner_charts) + " - " + account.getUsername() + "@" + account.getInstance());
}else{
} else {
toolbar_title.setText(R.string.owner_charts);
}
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, OwnerNotificationChartsActivity.this);
}
@ -162,19 +162,19 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
chart = findViewById(R.id.chart);
settings_time_from = findViewById(R.id.settings_time_from);
settings_time_to = findViewById(R.id.settings_time_to);
loader = findViewById(R.id.loader);
loader = findViewById(R.id.loader);
validate = findViewById(R.id.validate);
LinearLayout date_container = findViewById(R.id.date_container);
SQLiteDatabase db = Sqlite.getInstance(OwnerNotificationChartsActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
if( status_id == null) {
if (status_id == null) {
dateIni = new NotificationCacheDAO(OwnerNotificationChartsActivity.this, db).getSmallerDate();
dateEnd = new NotificationCacheDAO(OwnerNotificationChartsActivity.this, db).getGreaterDate();
}else{
} else {
Status status = new StatusCacheDAO(getApplicationContext(), db).getStatus(status_id);
if( status == null){
if (status == null) {
finish();
return;
}else{
} else {
dateIni = status.getCreated_at();
dateEnd = dateIni;
date_container.setVisibility(View.GONE);
@ -183,15 +183,15 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
int style;
if( theme == Helper.THEME_DARK){
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
}else if( theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
Calendar c = Calendar.getInstance();
if(dateIni != null) {
if (dateIni != null) {
c.setTime(dateIni);
}
int yearIni = c.get(Calendar.YEAR);
@ -207,7 +207,7 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
}
});
if( dateIni != null) {
if (dateIni != null) {
Calendar ce = Calendar.getInstance();
c.setTime(dateEnd);
int yearEnd = ce.get(Calendar.YEAR);
@ -264,24 +264,24 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
Iterator it = charts.getReblogs().entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
boostsEntry.add(new Entry((long)pair.getKey(), (int)pair.getValue()));
Map.Entry pair = (Map.Entry) it.next();
boostsEntry.add(new Entry((long) pair.getKey(), (int) pair.getValue()));
it.remove();
}
List<Entry> favEntry = new ArrayList<>();
it = charts.getFavourites().entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
favEntry.add(new Entry((long)pair.getKey(), (int)pair.getValue()));
Map.Entry pair = (Map.Entry) it.next();
favEntry.add(new Entry((long) pair.getKey(), (int) pair.getValue()));
it.remove();
}
List<Entry> mentionEntry = new ArrayList<>();
it = charts.getMentions().entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
mentionEntry.add(new Entry((long)pair.getKey(), (int)pair.getValue()));
Map.Entry pair = (Map.Entry) it.next();
mentionEntry.add(new Entry((long) pair.getKey(), (int) pair.getValue()));
it.remove();
}
@ -289,8 +289,8 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
List<Entry> followEntry = new ArrayList<>();
it = charts.getFollows().entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
followEntry.add(new Entry((long)pair.getKey(), (int)pair.getValue()));
Map.Entry pair = (Map.Entry) it.next();
followEntry.add(new Entry((long) pair.getKey(), (int) pair.getValue()));
it.remove();
}
@ -303,7 +303,6 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
}*/
LineDataSet dataSetBoosts = new LineDataSet(boostsEntry, getString(R.string.reblog));
dataSetBoosts.setColor(ContextCompat.getColor(OwnerNotificationChartsActivity.this, R.color.chart_notif_boost));
dataSetBoosts.setValueTextSize(10f);
@ -314,9 +313,9 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
dataSetBoosts.setDrawCircles(false);
dataSetBoosts.setDrawCircleHole(false);
dataSetBoosts.setLineWidth(2f);
if( status_id == null) {
if (status_id == null) {
dataSetBoosts.setMode(LineDataSet.Mode.CUBIC_BEZIER);
}else{
} else {
dataSetBoosts.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
}
@ -330,9 +329,9 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
dateSetFavorites.setDrawCircles(false);
dateSetFavorites.setDrawCircleHole(false);
dateSetFavorites.setLineWidth(2f);
if( status_id == null) {
if (status_id == null) {
dateSetFavorites.setMode(LineDataSet.Mode.CUBIC_BEZIER);
}else{
} else {
dateSetFavorites.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
}
@ -346,9 +345,9 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
dataSetMention.setDrawCircles(false);
dataSetMention.setDrawCircleHole(false);
dataSetMention.setLineWidth(2f);
if( status_id == null) {
if (status_id == null) {
dataSetMention.setMode(LineDataSet.Mode.CUBIC_BEZIER);
}else{
} else {
dataSetMention.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
}
@ -363,9 +362,9 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
dataSetFollow.setDrawCircles(false);
dataSetFollow.setDrawCircleHole(false);
dataSetFollow.setLineWidth(2f);
if( status_id == null) {
if (status_id == null) {
dataSetFollow.setMode(LineDataSet.Mode.CUBIC_BEZIER);
}else{
} else {
dataSetFollow.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
}
@ -420,14 +419,14 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
description.setEnabled(false);
//Update colors
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
xAxis.setTextColor(Color.BLACK);
dataSetBoosts.setValueTextColor(Color.BLACK);
dateSetFavorites.setValueTextColor(Color.BLACK);
dataSetFollow.setValueTextColor(Color.BLACK);
dataSetMention.setValueTextColor(Color.BLACK);
// dataSetPolls.setValueTextColor(Color.BLACK);
// dataSetPolls.setValueTextColor(Color.BLACK);
legend.setTextColor(Color.BLACK);
leftAxis.setTextColor(Color.BLACK);
@ -440,7 +439,7 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
dateSetFavorites.setValueTextColor(color);
dataSetFollow.setValueTextColor(color);
dataSetMention.setValueTextColor(color);
// dataSetPolls.setValueTextColor(color);
// dataSetPolls.setValueTextColor(color);
legend.setTextColor(color);
leftAxis.setTextColor(color);
}
@ -463,24 +462,27 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
public CustomMarkerView(Context context, int layoutResource) {
super(context, layoutResource);
tvContent = findViewById(R.id.tvContent);
if( theme == Helper.THEME_DARK){
if (theme == Helper.THEME_DARK) {
tvContent.setTextColor(ContextCompat.getColor(context, R.color.dark_text));
}else if( theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
tvContent.setTextColor(ContextCompat.getColor(context, R.color.dark_text));
}else {
} else {
tvContent.setTextColor(ContextCompat.getColor(context, R.color.black));
}
}
@Override
public void refreshContent(Entry e, Highlight highlight) {
Date date = new Date(((long) e.getX()));
tvContent.setText(String.valueOf(Helper.shortDateToString(date) + " - " +(int)e.getY()));
tvContent.setText(String.valueOf(Helper.shortDateToString(date) + " - " + (int) e.getY()));
super.refreshContent(e, highlight);
}
private MPPointF mOffset;
@Override
public MPPointF getOffset() {
if(mOffset == null) {
if (mOffset == null) {
mOffset = new MPPointF(-(getWidth() / 2), -getHeight());
}
return mOffset;
@ -525,7 +527,7 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
}
}
private void loadGraph(Date dateIni, Date dateEnd){
private void loadGraph(Date dateIni, Date dateEnd) {
String dateInitString = Helper.shortDateToString(dateIni);
String dateEndString = Helper.shortDateToString(dateEnd);
@ -544,19 +546,19 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
}
public class MyXAxisValueFormatter extends ValueFormatter {
private DateFormat mDataFormat;
private Date mDate;
MyXAxisValueFormatter() {
if( status_id == null) {
if (status_id == null) {
this.mDataFormat = new SimpleDateFormat("dd.MM", Locale.getDefault());
}else{
} else {
this.mDataFormat = new SimpleDateFormat("hh'h'", Locale.getDefault());
}
this.mDate = new Date();
}
@Override
public String getFormattedValue(float value) {
return getDateString((long) value);
@ -566,7 +568,7 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
try {
mDate.setTime(timestamp);
return mDataFormat.format(mDate);
} catch(Exception ex) {
} catch (Exception ex) {
return "xx";
}
}

View File

@ -26,6 +26,7 @@ import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@ -34,6 +35,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@ -111,7 +113,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
break;
@ -133,12 +135,12 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
new IntentFilter(Helper.INTENT_BACKUP_FINISH));
Toolbar toolbar = findViewById(R.id.toolbar);
if( theme == Helper.THEME_BLACK)
if (theme == Helper.THEME_BLACK)
toolbar.setBackgroundColor(ContextCompat.getColor(OwnerStatusActivity.this, R.color.black));
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ){
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(android.content.Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.toot_action_bar, new LinearLayout(getApplicationContext()), false);
@ -154,16 +156,16 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
});
TextView toolbarTitle = actionBar.getCustomView().findViewById(R.id.toolbar_title);
pp_actionBar = actionBar.getCustomView().findViewById(R.id.pp_actionBar);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Helper.colorizeToolbar(actionBar.getCustomView().findViewById(R.id.toolbar), R.color.black, OwnerStatusActivity.this);
}
toolbarTitle.setText(getString(R.string.owner_cached_toots));
}
statuses = new ArrayList<>();
RecyclerView lv_status = findViewById(R.id.lv_status);
mainLoader = findViewById(R.id.loader);
mainLoader = findViewById(R.id.loader);
nextElementLoader = findViewById(R.id.loading_next_status);
textviewNoAction = findViewById(R.id.no_action);
textviewNoAction = findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
max_id = null;
@ -179,22 +181,22 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
lv_status.setLayoutManager(mLayoutManager);
if( theme == Helper.THEME_DARK){
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
}else if( theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
SQLiteDatabase db = Sqlite.getInstance(OwnerStatusActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account account = new AccountDAO(OwnerStatusActivity.this,db).getUniqAccount(userId, instance);
Account account = new AccountDAO(OwnerStatusActivity.this, db).getUniqAccount(userId, instance);
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
swipeRefreshLayout = findViewById(R.id.swipeContainer);
new RetrieveFeedsAsyncTask(OwnerStatusActivity.this, filterToots, null, OwnerStatusActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
R.color.mastodonC2,
@ -226,14 +228,13 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
});
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if(dy > 0){
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
if(!flag_loading ) {
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
new RetrieveFeedsAsyncTask(OwnerStatusActivity.this, filterToots, max_id, OwnerStatusActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
nextElementLoader.setVisibility(View.VISIBLE);
@ -253,7 +254,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
getMenuInflater().inflate(R.menu.option_owner_cache, menu);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_LIGHT)
if (theme == Helper.THEME_LIGHT)
Helper.colorizeIconMenu(menu, R.color.black);
return true;
}
@ -283,6 +284,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
}
};
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -299,9 +301,9 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(OwnerStatusActivity.this, style);
@ -317,9 +319,9 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
}
});
dialogBuilder.create().show();
if( statistics == null) {
if (statistics == null) {
new RetrieveStatsAsyncTask(getApplicationContext(), OwnerStatusActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
} else {
displayStats();
}
return true;
@ -328,9 +330,9 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
dialogBuilder = new AlertDialog.Builder(OwnerStatusActivity.this, style);
@ -340,11 +342,11 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
SQLiteDatabase db = Sqlite.getInstance(OwnerStatusActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
if( dateIni == null)
if (dateIni == null)
dateIni = new StatusCacheDAO(OwnerStatusActivity.this, db).getSmallerDate(StatusCacheDAO.ARCHIVE_CACHE);
if( dateEnd == null)
if (dateEnd == null)
dateEnd = new StatusCacheDAO(OwnerStatusActivity.this, db).getGreaterDate(StatusCacheDAO.ARCHIVE_CACHE);
if( dateIni == null || dateEnd == null)
if (dateIni == null || dateEnd == null)
return true;
String dateInitString = Helper.shortDateToString(dateIni);
String dateEndString = Helper.shortDateToString(dateEnd);
@ -378,7 +380,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
settings_time_from.setText(dateInitString);
settings_time_to.setText(dateEndString);
if( filterToots.getFilter() != null)
if (filterToots.getFilter() != null)
filter_keywords.setText(filterToots.getFilter());
Calendar c = Calendar.getInstance();
@ -429,7 +431,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
filterToots.setDateIni(Helper.dateToString(dateIni));
filterToots.setDateEnd(Helper.dateToString(dateEnd));
if( filter_keywords.getText() != null && filter_keywords.getText().toString().trim().length() > 0)
if (filter_keywords.getText() != null && filter_keywords.getText().toString().trim().length() > 0)
filterToots.setFilter(filter_keywords.getText().toString());
else
filterToots.setFilter(null);
@ -460,8 +462,8 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
//Discards 404 - error which can often happen due to toots which have been deleted
if( apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 ){
Toasty.error(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
if (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404) {
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false);
swiped = false;
flag_loading = false;
@ -470,13 +472,13 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
int previousPosition = this.statuses.size();
List<Status> statuses = apiResponse.getStatuses();
max_id = apiResponse.getMax_id();
flag_loading = (max_id == null );
if( !swiped && firstLoad && (statuses == null || statuses.size() == 0))
flag_loading = (max_id == null);
if (!swiped && firstLoad && (statuses == null || statuses.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
else
textviewNoAction.setVisibility(View.GONE);
if( swiped ){
if (swiped) {
if (previousPosition > 0) {
for (int i = 0; i < previousPosition; i++) {
this.statuses.remove(0);
@ -485,11 +487,11 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
}
swiped = false;
}
if( statuses != null && statuses.size() > 0) {
if (statuses != null && statuses.size() > 0) {
this.statuses.addAll(statuses);
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
}else {
if( textviewNoAction.getVisibility() != View.VISIBLE && firstLoad) {
} else {
if (textviewNoAction.getVisibility() != View.VISIBLE && firstLoad) {
RelativeLayout no_result = findViewById(R.id.no_result);
no_result.setVisibility(View.VISIBLE);
}
@ -524,8 +526,8 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
displayStats();
}
private void displayStats(){
if( statsDialogView != null){
private void displayStats() {
if (statsDialogView != null) {
ScrollView stats_container = statsDialogView.findViewById(R.id.stats_container);
RelativeLayout loader = statsDialogView.findViewById(R.id.loader);
@ -547,7 +549,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
TextView tags = statsDialogView.findViewById(R.id.tags);
ImageButton charts = statsDialogView.findViewById(R.id.charts);
charts.setOnClickListener(w ->{
charts.setOnClickListener(w -> {
Intent intent = new Intent(OwnerStatusActivity.this, OwnerChartsActivity.class);
startActivity(intent);
});
@ -570,26 +572,26 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
DecimalFormat df = new DecimalFormat("#.##");
frequency.setText(getString(R.string.toot_per_day, df.format(statistics.getFrequency())));
if( statistics.getTagsTrend() != null && statistics.getTagsTrend().size() > 0 ){
Iterator it = statistics.getTagsTrend() .entrySet().iterator();
if (statistics.getTagsTrend() != null && statistics.getTagsTrend().size() > 0) {
Iterator it = statistics.getTagsTrend().entrySet().iterator();
StringBuilder text = new StringBuilder();
int i = 1;
while (it.hasNext() && i <= 10) {
Map.Entry pair = (Map.Entry)it.next();
Map.Entry pair = (Map.Entry) it.next();
System.out.println(pair.getKey() + " = " + pair.getValue());
text.append(i).append(" - ").append(pair.getKey()).append("").append(pair.getValue()).append("\r\n");
i++;
}
tags.setText(text.toString());
}else{
} else {
tags.setText(getString(R.string.no_tags));
}
stats_container.setVisibility(View.VISIBLE);
loader.setVisibility(View.GONE);
}else{
Toasty.error(getApplicationContext(),getString(R.string.toast_error),Toast.LENGTH_SHORT).show();
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_SHORT).show();
}
}
}

View File

@ -20,8 +20,10 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.MenuItem;
@ -66,7 +68,7 @@ public class PartnerShipActivity extends BaseActivity implements OnRetrieveRemot
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -80,14 +82,14 @@ public class PartnerShipActivity extends BaseActivity implements OnRetrieveRemot
setTheme(R.style.AppThemeDark);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_partnership);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
@ -99,7 +101,7 @@ public class PartnerShipActivity extends BaseActivity implements OnRetrieveRemot
}
});
toolbar_title.setText(R.string.action_partnership);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, PartnerShipActivity.this);
}
@ -113,11 +115,11 @@ public class PartnerShipActivity extends BaseActivity implements OnRetrieveRemot
ImageView mastohost = findViewById(R.id.mastohost_logo);
mastohost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://masto.host"));
startActivity(browserIntent);
}
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://masto.host"));
startActivity(browserIntent);
}
});
setTitle(R.string.action_partnership);
@ -129,7 +131,7 @@ public class PartnerShipActivity extends BaseActivity implements OnRetrieveRemot
new RetrieveRemoteDataAsyncTask(getApplicationContext(), "mastohost", "mastodon.social", PartnerShipActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
@ -146,13 +148,13 @@ public class PartnerShipActivity extends BaseActivity implements OnRetrieveRemot
@Override
public void onRetrieveRemoteAccount(Results results) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
if( results == null){
Toasty.error(getApplicationContext(), getString(R.string.toast_error),Toast.LENGTH_LONG).show();
if (results == null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
List<Account> accounts = results.getAccounts();
Account account;
if( accounts != null && accounts.size() > 0){
if (accounts != null && accounts.size() > 0) {
account = accounts.get(0);
account.setFollowing(true);
switch (account.getUsername()) {
@ -161,17 +163,17 @@ public class PartnerShipActivity extends BaseActivity implements OnRetrieveRemot
mastohostAdapter.notifyDataSetChanged();
break;
}
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),PartnerShipActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(), PartnerShipActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@Override
public void onResume(){
public void onResume() {
super.onResume();
if( mastohostAcct != null){
for(Account account: mastohostAcct){
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),PartnerShipActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (mastohostAcct != null) {
for (Account account : mastohostAcct) {
new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(), PartnerShipActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}
@ -180,11 +182,11 @@ public class PartnerShipActivity extends BaseActivity implements OnRetrieveRemot
public void onRetrieveRelationship(Relationship relationship, Error error) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, "");
if( error != null){
if (error != null) {
return;
}
for( int i = 0 ; i < mastohostAcct.size() ; i++){
if( mastohostAcct.get(i).getId() != null && mastohostAcct.get(i).getId().equals(relationship.getId())){
for (int i = 0; i < mastohostAcct.size(); i++) {
if (mastohostAcct.get(i).getId() != null && mastohostAcct.get(i).getId().equals(relationship.getId())) {
mastohostAcct.get(i).setFollowing(relationship.isFollowing() || userId.trim().equals(relationship.getId()));
mastohostAdapter.notifyDataSetChanged();
break;

View File

@ -41,6 +41,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.appcompat.widget.PopupMenu;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.Menu;
@ -143,16 +144,17 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
private ImageView my_pp, send;
private TextView add_comment_read;
private EditText add_comment_write;
private String instance;
private String instance;
private List<String> playlistForVideo;
private List<Playlist> playlists;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
fullscreen = FullScreenMediaController.fullscreen.OFF;
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -185,7 +187,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
add_comment_read = findViewById(R.id.add_comment_read);
add_comment_write = findViewById(R.id.add_comment_write);
peertube_playlist = findViewById(R.id.peertube_playlist);
send = findViewById(R.id.send);
send = findViewById(R.id.send);
add_comment_read.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -198,10 +200,10 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
});
Helper.changeDrawableColor(getApplicationContext(), send, R.color.mastodonC4);
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
write_comment_container.setVisibility(View.GONE);
}
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
peertube_playlist.setVisibility(View.VISIBLE);
peertube_bookmark.setVisibility(View.GONE);
}
@ -210,7 +212,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
@Override
public void onClick(View v) {
String comment = add_comment_write.getText().toString();
if( comment.trim().length() > 0 ) {
if (comment.trim().length() > 0) {
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
add_comment_write.setText("");
add_comment_read.setVisibility(View.VISIBLE);
@ -227,17 +229,17 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
Helper.loadGiF(getApplicationContext(), account.getAvatar(), my_pp);
Bundle b = getIntent().getExtras();
if(b != null) {
if (b != null) {
peertubeInstance = b.getString("peertube_instance", null);
videoId = b.getString("video_id", null);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
@ -248,7 +250,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
finish();
}
});
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, PeertubeActivity.this);
}
@ -256,9 +258,9 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_DIRECT);
if( mode != Helper.VIDEO_MODE_WEBVIEW && mode != Helper.VIDEO_MODE_DIRECT)
if (mode != Helper.VIDEO_MODE_WEBVIEW && mode != Helper.VIDEO_MODE_DIRECT)
mode = Helper.VIDEO_MODE_DIRECT;
if( mode == Helper.VIDEO_MODE_WEBVIEW){
if (mode == Helper.VIDEO_MODE_WEBVIEW) {
webview_video.setVisibility(View.VISIBLE);
playerView.setVisibility(View.GONE);
@ -299,34 +301,34 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
webview_video.setWebViewClient(new MastalabWebViewClient(PeertubeActivity.this));
webview_video.loadUrl("https://" + peertubeInstance + "/videos/embed/" + videoId);
}else {
} else {
webview_video.setVisibility(View.GONE);
playerView.setVisibility(View.VISIBLE);
loader.setVisibility(View.VISIBLE);
}
if( mode != Helper.VIDEO_MODE_WEBVIEW){
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
playerView.setControllerShowTimeoutMs(1000);
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
initFullscreenDialog();
initFullscreenButton();
}
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
new ManagePlaylistsAsyncTask(PeertubeActivity.this,GET_PLAYLIST, null, null, null , PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST, null, null, null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
new RetrievePeertubeSingleAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
public void change(){
if(fullscreen == FullScreenMediaController.fullscreen.ON){
public void change() {
if (fullscreen == FullScreenMediaController.fullscreen.ON) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Objects.requireNonNull(getSupportActionBar()).hide();
peertube_information_container.setVisibility(View.GONE);
}else{
} else {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
Objects.requireNonNull(getSupportActionBar()).show();
@ -358,7 +360,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
public static void hideKeyboard(Activity activity) {
if (activity != null && activity.getWindow() != null && activity.getWindow().getDecorView() != null) {
InputMethodManager imm = (InputMethodManager)activity.getSystemService(INPUT_METHOD_SERVICE);
InputMethodManager imm = (InputMethodManager) activity.getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
}
}
@ -371,15 +373,16 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
menu.findItem(R.id.action_comment).setVisible(true);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_LIGHT)
if (theme == Helper.THEME_LIGHT)
Helper.colorizeIconMenu(menu, R.color.black);
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
MenuItem item = menu.findItem(R.id.action_comment);
if( item != null)
if (item != null)
item.setVisible(false);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -387,7 +390,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
finish();
return true;
case R.id.action_comment:
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
Toasty.info(getApplicationContext(), getString(R.string.retrieve_remote_status), Toast.LENGTH_LONG).show();
new AsyncTask<Void, Void, Void>() {
@ -423,9 +426,9 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
contextReference.get().startActivity(intent);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
if(! peertube.isCommentsEnabled()) {
Toasty.info(getApplicationContext(), getString(R.string.comment_no_allowed_peertube),Toast.LENGTH_LONG).show();
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
if (!peertube.isCommentsEnabled()) {
Toasty.info(getApplicationContext(), getString(R.string.comment_no_allowed_peertube), Toast.LENGTH_LONG).show();
return true;
}
int style;
@ -433,9 +436,9 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
AlertDialog.Builder builderInner;
@ -449,15 +452,15 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
builderInner.setView(input);
builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderInner.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
public void onClick(DialogInterface dialog, int which) {
String comment = input.getText().toString();
if( comment.trim().length() > 0 ) {
if (comment.trim().length() > 0) {
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog.dismiss();
}
@ -482,31 +485,31 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
@Override
public void onRetrievePeertube(APIResponse apiResponse) {
if( apiResponse == null || (apiResponse.getError() != null) || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0){
Toasty.error(getApplicationContext(), getString(R.string.toast_error),Toast.LENGTH_LONG).show();
if (apiResponse == null || (apiResponse.getError() != null) || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
loader.setVisibility(View.GONE);
return;
}
if( apiResponse.getPeertubes() == null || apiResponse.getPeertubes().get(0) == null || apiResponse.getPeertubes().get(0).getFileUrl(null) == null){
Toasty.error(getApplicationContext(), getString(R.string.toast_error),Toast.LENGTH_LONG).show();
if (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().get(0) == null || apiResponse.getPeertubes().get(0).getFileUrl(null) == null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
loader.setVisibility(View.GONE);
return;
}
peertube = apiResponse.getPeertubes().get(0);
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
new ManagePlaylistsAsyncTask(PeertubeActivity.this,GET_PLAYLIST_FOR_VIDEO, null, peertube.getId(), null , PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST_FOR_VIDEO, null, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
peertube_playlist.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( playlists != null && peertube.getId() != null) {
if (playlists != null && peertube.getId() != null) {
PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist);
for(Playlist playlist: playlists){
for (Playlist playlist : playlists) {
String title = null;
for (String id : playlistForVideo) {
if (playlist.getId().equals(id)) {
@ -514,7 +517,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
break;
}
}
if( title == null){
if (title == null) {
title = playlist.getDisplayName();
}
MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title);
@ -534,13 +537,13 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
return false;
}
});
if(playlistForVideo.contains(playlist.getId())){
if (playlistForVideo.contains(playlist.getId())) {
item.setTitle(playlist.getDisplayName());
new ManagePlaylistsAsyncTask(PeertubeActivity.this,ManagePlaylistsAsyncTask.action.DELETE_VIDEOS, playlist, peertube.getId(), null , PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.DELETE_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
playlistForVideo.remove(playlist.getId());
}else{
item.setTitle( "" + playlist.getDisplayName());
new ManagePlaylistsAsyncTask(PeertubeActivity.this,ManagePlaylistsAsyncTask.action.ADD_VIDEOS, playlist, peertube.getId(), null , PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
item.setTitle("" + playlist.getDisplayName());
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.ADD_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
playlistForVideo.add(playlist.getId());
}
return false;
@ -553,12 +556,11 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
});
if( peertube.isCommentsEnabled()) {
if (peertube.isCommentsEnabled()) {
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
write_comment_container.setVisibility(View.VISIBLE);
}else {
} else {
RelativeLayout no_action = findViewById(R.id.no_action);
TextView no_action_text = findViewById(R.id.no_action_text);
no_action_text.setText(getString(R.string.comment_no_allowed_peertube));
@ -578,11 +580,11 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
changeColor();
initResolution();
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
peertube_like_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String newState = peertube.getMyRating().equals("like")?"none":"like";
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
peertube.setMyRating(newState);
changeColor();
@ -591,20 +593,20 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
peertube_dislike_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String newState = peertube.getMyRating().equals("dislike")?"none":"dislike";
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
peertube.setMyRating(newState);
changeColor();
}
});
}else{
} else {
peertube_like_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String newState = peertube.getMyRating().equals("like")?"none":"like";
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
Status status = new Status();
status.setUri("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid());
CrossActions.doCrossAction(getApplicationContext(), RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE, status, null, API.StatusAction.FAVOURITE, null, PeertubeActivity.this, true);
CrossActions.doCrossAction(getApplicationContext(), RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE, status, null, API.StatusAction.FAVOURITE, null, PeertubeActivity.this, true);
peertube.setMyRating(newState);
changeColor();
}
@ -612,10 +614,10 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
peertube_dislike_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String newState = peertube.getMyRating().equals("dislike")?"none":"dislike";
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
Status status = new Status();
status.setUri("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid());
CrossActions.doCrossAction(getApplicationContext(), RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE, status, null, API.StatusAction.UNFAVOURITE, null, PeertubeActivity.this, true);
CrossActions.doCrossAction(getApplicationContext(), RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE, status, null, API.StatusAction.UNFAVOURITE, null, PeertubeActivity.this, true);
peertube.setMyRating(newState);
changeColor();
}
@ -630,7 +632,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
e.printStackTrace();
}
if( mode == Helper.VIDEO_MODE_DIRECT){
if (mode == Helper.VIDEO_MODE_DIRECT) {
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(),
Util.getUserAgent(getApplicationContext(), "Mastalab"), null);
@ -647,17 +649,16 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
peertube_download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(Build.VERSION.SDK_INT >= 23 ){
if (Build.VERSION.SDK_INT >= 23) {
if (ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PeertubeActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
} else {
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null));
}
}else{
} else {
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null));
}
}
@ -667,7 +668,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
Drawable img;
if( peertubes == null || peertubes.size() == 0)
if (peertubes == null || peertubes.size() == 0)
img = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube_border);
else
img = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube);
@ -677,17 +678,17 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
@Override
public void onClick(View v) {
List<Peertube> peertubes = new PeertubeFavoritesDAO(PeertubeActivity.this, db).getSinglePeertube(peertube);
if( peertubes == null || peertubes.size() == 0){
if (peertubes == null || peertubes.size() == 0) {
new PeertubeFavoritesDAO(PeertubeActivity.this, db).insert(peertube);
Toasty.success(getApplicationContext(),getString(R.string.bookmark_add_peertube), Toast.LENGTH_SHORT).show();
}else{
Toasty.success(getApplicationContext(), getString(R.string.bookmark_add_peertube), Toast.LENGTH_SHORT).show();
} else {
new PeertubeFavoritesDAO(PeertubeActivity.this, db).remove(peertube);
Toasty.success(getApplicationContext(),getString(R.string.bookmark_remove_peertube), Toast.LENGTH_SHORT).show();
Toasty.success(getApplicationContext(), getString(R.string.bookmark_remove_peertube), Toast.LENGTH_SHORT).show();
}
if( peertubes != null && peertubes.size() > 0) //Was initially in cache
peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds( null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube_border), null ,null);
if (peertubes != null && peertubes.size() > 0) //Was initially in cache
peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube_border), null, null);
else
peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds( null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube), null ,null);
peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube), null, null);
}
});
@ -698,11 +699,11 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.shared_via));
String url;
url = "https://" +peertube.getInstance() + "/videos/watch/"+ peertube.getUuid();
url = "https://" + peertube.getInstance() + "/videos/watch/" + peertube.getUuid();
boolean share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true);
String extra_text;
if( share_details) {
extra_text = "@" +peertube.getAccount().getAcct();
if (share_details) {
extra_text = "@" + peertube.getAccount().getAcct();
extra_text += "\r\n\r\n" + peertube.getName();
extra_text += "\n\n" + Helper.shortnameToUnicode(":link:", true) + " " + url + "\r\n-\n";
final String contentToot;
@ -712,7 +713,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
//noinspection deprecation
contentToot = Html.fromHtml(peertube.getDescription()).toString();
extra_text += contentToot;
}else {
} else {
extra_text = url;
}
sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text);
@ -727,7 +728,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if( mode != Helper.VIDEO_MODE_WEBVIEW) {
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
openFullscreenDialog();
setFullscreen(FullScreenMediaController.fullscreen.ON);
@ -736,8 +737,8 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
setFullscreen(FullScreenMediaController.fullscreen.OFF);
}
change();
}else {
final ViewGroup videoLayout = findViewById(R.id.videoLayout);
} else {
final ViewGroup videoLayout = findViewById(R.id.videoLayout);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
setFullscreen(FullScreenMediaController.fullscreen.ON);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
@ -752,22 +753,22 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
@Override
public void onRetrievePeertubeComments(APIResponse apiResponse) {
if( apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404) ){
if( apiResponse == null)
Toasty.error(getApplicationContext(), getString(R.string.toast_error),Toast.LENGTH_LONG).show();
if (apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404)) {
if (apiResponse == null)
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
else
Toasty.error(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return;
}
List<Status> statuses = apiResponse.getStatuses();
RecyclerView lv_comments = findViewById(R.id.peertube_comments);
if( statuses == null || statuses.size() == 0){
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
if (statuses == null || statuses.size() == 0) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
RelativeLayout no_action = findViewById(R.id.no_action);
no_action.setVisibility(View.VISIBLE);
lv_comments.setVisibility(View.GONE);
}
}else {
} else {
lv_comments.setVisibility(View.VISIBLE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
boolean isOnWifi = Helper.isOnWIFI(PeertubeActivity.this);
@ -789,43 +790,43 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
@Override
public void onDestroy() {
super.onDestroy();
if( player != null)
if (player != null)
player.release();
}
@Override
protected void onPause() {
super.onPause();
if( player != null) {
if (player != null) {
player.setPlayWhenReady(false);
}
}
@Override
public void onResume(){
public void onResume() {
super.onResume();
if( player != null) {
if (player != null) {
player.setPlayWhenReady(true);
}
}
public void displayResolution(){
public void displayResolution() {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
AlertDialog.Builder builderSingle = new AlertDialog.Builder(PeertubeActivity.this, style);
builderSingle.setTitle(R.string.pickup_resolution);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(PeertubeActivity.this, android.R.layout.select_dialog_item);
for(String resolution: peertube.getResolution())
arrayAdapter.add(resolution+"p");
for (String resolution : peertube.getResolution())
arrayAdapter.add(resolution + "p");
builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@ -837,14 +838,14 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
public void onClick(DialogInterface dialog, int which) {
String res = arrayAdapter.getItem(which).substring(0, arrayAdapter.getItem(which).length() - 1);
if( playerView != null) {
if (playerView != null) {
loader.setVisibility(View.VISIBLE);
long position = player.getCurrentPosition();
PlaybackControlView controlView = playerView.findViewById(R.id.exo_controller);
resolution = controlView.findViewById(R.id.resolution);
resolution.setText(String.format("%sp",res));
if( mode == Helper.VIDEO_MODE_DIRECT){
if( player != null)
resolution.setText(String.format("%sp", res));
if (mode == Helper.VIDEO_MODE_DIRECT) {
if (player != null)
player.release();
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
playerView.setPlayer(player);
@ -868,7 +869,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
@Override
public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) {
if( peertube.isCommentsEnabled() && statusAction == API.StatusAction.PEERTUBECOMMENT)
if (peertube.isCommentsEnabled() && statusAction == API.StatusAction.PEERTUBECOMMENT)
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@ -923,7 +924,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
private void initResolution() {
PlaybackControlView controlView = playerView.findViewById(R.id.exo_controller);
resolution = controlView.findViewById(R.id.resolution);
resolution.setText(String.format("%sp",peertube.getResolution().get(0)));
resolution.setText(String.format("%sp", peertube.getResolution().get(0)));
resolution.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -933,30 +934,29 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
private void changeColor(){
if( peertube.getMyRating() != null && peertube.getMyRating().equals("like")){
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_up_peertube,R.color.positive_thumbs);
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_down_peertube,R.color.neutral_thumbs);
}else if( peertube.getMyRating() != null && peertube.getMyRating().equals("dislike")){
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_up_peertube,R.color.neutral_thumbs);
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_down_peertube,R.color.negative_thumbs);
}else {
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_up_peertube,R.color.neutral_thumbs);
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_down_peertube,R.color.neutral_thumbs);
private void changeColor() {
if (peertube.getMyRating() != null && peertube.getMyRating().equals("like")) {
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_up_peertube, R.color.positive_thumbs);
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_down_peertube, R.color.neutral_thumbs);
} else if (peertube.getMyRating() != null && peertube.getMyRating().equals("dislike")) {
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_up_peertube, R.color.neutral_thumbs);
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_down_peertube, R.color.negative_thumbs);
} else {
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_up_peertube, R.color.neutral_thumbs);
changeDrawableColor(getApplicationContext(), R.drawable.ic_thumb_down_peertube, R.color.neutral_thumbs);
}
Drawable thumbUp = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_thumb_up_peertube);
Drawable thumbDown = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_thumb_down_peertube);
peertube_like_count.setCompoundDrawablesWithIntrinsicBounds( null, thumbUp, null, null);
peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds( null, thumbDown, null, null);
peertube_like_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbUp, null, null);
peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbDown, null, null);
}
@Override
public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
if( actionType == GET_PLAYLIST_FOR_VIDEO && apiResponse != null) {
if (actionType == GET_PLAYLIST_FOR_VIDEO && apiResponse != null) {
playlistForVideo = apiResponse.getPlaylistForVideos();
}else if( actionType == GET_PLAYLIST && apiResponse != null){
} else if (actionType == GET_PLAYLIST && apiResponse != null) {
playlists = apiResponse.getPlaylists();
}
}

View File

@ -21,9 +21,11 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -86,7 +88,7 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -101,19 +103,19 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
}
Bundle b = getIntent().getExtras();
if(b != null) {
if (b != null) {
videoId = b.getString("video_id", null);
}
if( videoId == null){
if (videoId == null) {
videoId = sharedpreferences.getString(Helper.VIDEO_ID, null);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
@ -125,7 +127,7 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
}
});
toolbar_title.setText(R.string.update_video);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, PeertubeEditUploadActivity.this);
}
@ -147,7 +149,6 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
set_upload_enable_comments = findViewById(R.id.set_upload_enable_comments);
//Change spinner colors
Helper.changeMaterialSpinnerColor(PeertubeEditUploadActivity.this, set_upload_channel);
Helper.changeMaterialSpinnerColor(PeertubeEditUploadActivity.this, set_upload_categories);
@ -165,22 +166,22 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
builderInner = new AlertDialog.Builder(PeertubeEditUploadActivity.this, style);
builderInner.setMessage(getString(R.string.delete_video_confirmation));
builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
public void onClick(DialogInterface dialog, int which) {
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.PEERTUBEDELETEVIDEO, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
dialog.dismiss();
}
@ -189,23 +190,23 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
}
});
//Get params from the API
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
LinkedHashMap<String, String> translations = null;
if( peertubeInformation.getTranslations() != null)
if (peertubeInformation.getTranslations() != null)
translations = new LinkedHashMap<>(peertubeInformation.getTranslations());
//Populate catgories
String[] categoriesA = new String[categories.size()];
Iterator it = categories.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if( translations == null ||translations.size() == 0 || !translations.containsKey((String)pair.getValue()))
categoriesA[i] = (String)pair.getValue();
Map.Entry pair = (Map.Entry) it.next();
if (translations == null || translations.size() == 0 || !translations.containsKey((String) pair.getValue()))
categoriesA[i] = (String) pair.getValue();
else
categoriesA[i] = translations.get((String)pair.getValue());
categoriesA[i] = translations.get((String) pair.getValue());
it.remove();
i++;
}
@ -214,17 +215,16 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
set_upload_categories.setAdapter(adapterCatgories);
//Populate licenses
String[] licensesA = new String[licences.size()];
it = licences.entrySet().iterator();
i = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if( translations == null || translations.size() == 0 || !translations.containsKey((String)pair.getValue()))
licensesA[i] = (String)pair.getValue();
Map.Entry pair = (Map.Entry) it.next();
if (translations == null || translations.size() == 0 || !translations.containsKey((String) pair.getValue()))
licensesA[i] = (String) pair.getValue();
else
licensesA[i] = translations.get((String)pair.getValue());
licensesA[i] = translations.get((String) pair.getValue());
it.remove();
i++;
}
@ -238,11 +238,11 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
it = languages.entrySet().iterator();
i = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if( translations == null || translations.size() == 0 || !translations.containsKey((String)pair.getValue()))
languagesA[i] = (String)pair.getValue();
Map.Entry pair = (Map.Entry) it.next();
if (translations == null || translations.size() == 0 || !translations.containsKey((String) pair.getValue()))
languagesA[i] = (String) pair.getValue();
else
languagesA[i] = translations.get((String)pair.getValue());
languagesA[i] = translations.get((String) pair.getValue());
it.remove();
i++;
}
@ -256,11 +256,11 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
it = privacies.entrySet().iterator();
i = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if( translations == null || translations.size() == 0 || !translations.containsKey((String)pair.getValue()))
privaciesA[i] = (String)pair.getValue();
Map.Entry pair = (Map.Entry) it.next();
if (translations == null || translations.size() == 0 || !translations.containsKey((String) pair.getValue()))
privaciesA[i] = (String) pair.getValue();
else
privaciesA[i] = translations.get((String)pair.getValue());
privaciesA[i] = translations.get((String) pair.getValue());
it.remove();
i++;
}
@ -278,12 +278,10 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
}
@Override
public void onRetrievePeertube(APIResponse apiResponse) {
if( apiResponse.getError() != null || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0){
if ( apiResponse.getError() != null && apiResponse.getError().getError() != null)
if (apiResponse.getError() != null || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
else
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
@ -294,11 +292,11 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
//Peertube video
Peertube peertube = apiResponse.getPeertubes().get(0);
if( peertube.isUpdate()){
if (peertube.isUpdate()) {
Toasty.success(getApplicationContext(), getString(R.string.toast_peertube_video_updated), Toast.LENGTH_LONG).show();
peertube.setUpdate(false);
set_upload_submit.setEnabled(true);
}else {
} else {
new RetrievePeertubeChannelsAsyncTask(PeertubeEditUploadActivity.this, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@ -308,54 +306,54 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
categoryToSend = peertube.getCategory();
if( languageToSend == null){
if (languageToSend == null) {
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
Map.Entry<String,String> entryString = languages.entrySet().iterator().next();
Map.Entry<String, String> entryString = languages.entrySet().iterator().next();
languageToSend = new HashMap<>();
languageToSend.put(entryString.getKey(), entryString.getValue());
}
if( licenseToSend == null){
if (licenseToSend == null) {
LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
Map.Entry<Integer,String> entryInt = licences.entrySet().iterator().next();
Map.Entry<Integer, String> entryInt = licences.entrySet().iterator().next();
licenseToSend = new HashMap<>();
licenseToSend.put(entryInt.getKey(), entryInt.getValue());
}
if( categoryToSend == null){
if (categoryToSend == null) {
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
Map.Entry<Integer,String> entryInt = categories.entrySet().iterator().next();
Map.Entry<Integer, String> entryInt = categories.entrySet().iterator().next();
categoryToSend = new HashMap<>();
categoryToSend.put(entryInt.getKey(), entryInt.getValue());
}
if( privacyToSend == null){
if (privacyToSend == null) {
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
Map.Entry<Integer,String> entryInt = privacies.entrySet().iterator().next();
Map.Entry<Integer, String> entryInt = privacies.entrySet().iterator().next();
privacyToSend = new HashMap<>();
privacyToSend.put(entryInt.getKey(), entryInt.getValue());
}
String language = null;
if( languageToSend != null) {
if (languageToSend != null) {
Map.Entry<String, String> entryString = languageToSend.entrySet().iterator().next();
language = entryString.getValue();
}
String license = null;
if( licenseToSend != null) {
if (licenseToSend != null) {
Map.Entry<Integer, String> entryInt = licenseToSend.entrySet().iterator().next();
license = entryInt.getValue();
}
String privacy = null;
if( privacyToSend != null) {
if (privacyToSend != null) {
Map.Entry<Integer, String> entryInt = privacyToSend.entrySet().iterator().next();
privacy = entryInt.getValue();
}
String category = null;
if( categoryToSend != null) {
if (categoryToSend != null) {
Map.Entry<Integer, String> entryInt = categoryToSend.entrySet().iterator().next();
category = entryInt.getValue();
}
@ -377,49 +375,49 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
LinkedHashMap<String, String> translations = null;
if( peertubeInformation.getTranslations() != null)
if (peertubeInformation.getTranslations() != null)
translations = new LinkedHashMap<>(peertubeInformation.getTranslations());
int languagePosition = 0;
if( languages.containsValue(language)){
if (languages.containsValue(language)) {
Iterator it = languages.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if(pair.getValue().equals(language))
Map.Entry pair = (Map.Entry) it.next();
if (pair.getValue().equals(language))
break;
it.remove();
languagePosition++;
}
}
int privacyPosition = 0;
if( privacy != null && privacies.containsValue(privacy)){
if (privacy != null && privacies.containsValue(privacy)) {
Iterator it = privacies.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if(pair.getValue().equals(privacy))
Map.Entry pair = (Map.Entry) it.next();
if (pair.getValue().equals(privacy))
break;
it.remove();
privacyPosition++;
}
}
int licensePosition = 0;
if( license != null && licences.containsValue(license)){
if (license != null && licences.containsValue(license)) {
Iterator it = licences.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if(pair.getValue().equals(license))
Map.Entry pair = (Map.Entry) it.next();
if (pair.getValue().equals(license))
break;
it.remove();
licensePosition++;
}
}
int categoryPosition = 0;
if(category != null && categories.containsValue(category)){
if (category != null && categories.containsValue(category)) {
Iterator it = categories.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if(pair.getValue().equals(category))
Map.Entry pair = (Map.Entry) it.next();
if (pair.getValue().equals(category))
break;
it.remove();
categoryPosition++;
@ -434,10 +432,10 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
Iterator it = privaciesCheck.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if( i == position){
Map.Entry pair = (Map.Entry) it.next();
if (i == position) {
privacyToSend = new HashMap<>();
privacyToSend.put((Integer)pair.getKey(), (String)pair.getValue());
privacyToSend.put((Integer) pair.getKey(), (String) pair.getValue());
break;
}
it.remove();
@ -453,10 +451,10 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
Iterator it = licensesCheck.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if( i == position){
Map.Entry pair = (Map.Entry) it.next();
if (i == position) {
licenseToSend = new HashMap<>();
licenseToSend.put((Integer)pair.getKey(), (String)pair.getValue());
licenseToSend.put((Integer) pair.getKey(), (String) pair.getValue());
break;
}
it.remove();
@ -472,10 +470,10 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
Iterator it = categoriesCheck.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if( i == position){
Map.Entry pair = (Map.Entry) it.next();
if (i == position) {
categoryToSend = new HashMap<>();
categoryToSend.put((Integer)pair.getKey(), (String)pair.getValue());
categoryToSend.put((Integer) pair.getKey(), (String) pair.getValue());
break;
}
it.remove();
@ -491,10 +489,10 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
Iterator it = languagesCheck.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if( i == position){
Map.Entry pair = (Map.Entry) it.next();
if (i == position) {
languageToSend = new HashMap<>();
languageToSend.put((String)pair.getKey(), (String)pair.getValue());
languageToSend.put((String) pair.getKey(), (String) pair.getValue());
break;
}
it.remove();
@ -512,10 +510,10 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
Iterator it = channelsCheck.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if( i == position){
Map.Entry pair = (Map.Entry) it.next();
if (i == position) {
channelToSend = new HashMap<>();
channelToSend.put((String)pair.getKey(), (String)pair.getValue());
channelToSend.put((String) pair.getKey(), (String) pair.getValue());
break;
}
@ -555,7 +553,7 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
set_upload_categories.setSelectedIndex(categoryPosition);
List<String> tags = peertube.getTags();
if( tags != null && tags.size() > 0) {
if (tags != null && tags.size() > 0) {
String[] tagsA = tags.toArray(new String[tags.size()]);
p_video_tags.setTags(tagsA);
}
@ -569,8 +567,8 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
@Override
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
if( apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0){
if ( apiResponse.getError().getError() != null)
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
if (apiResponse.getError().getError() != null)
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
else
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
@ -581,8 +579,8 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
List<Account> accounts = apiResponse.getAccounts();
String[] channelName = new String[accounts.size()];
int i = 0;
for(Account account: accounts){
channels.put(account.getUsername(),account.getId());
for (Account account : accounts) {
channels.put(account.getUsername(), account.getId());
channelName[i] = account.getUsername();
i++;
}
@ -591,14 +589,14 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
set_upload_channel.setAdapter(adapterChannel);
int channelPosition = 0;
if( channels.containsKey(channel.getUsername())){
if (channels.containsKey(channel.getUsername())) {
LinkedHashMap<String, String> channelsIterator = new LinkedHashMap<>(channels);
Iterator it = channelsIterator.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if(pair.getKey().equals(channel.getUsername())) {
Map.Entry pair = (Map.Entry) it.next();
if (pair.getKey().equals(channel.getUsername())) {
channelToSend = new HashMap<>();
channelToSend.put((String)pair.getKey(), (String)pair.getValue());
channelToSend.put((String) pair.getKey(), (String) pair.getValue());
break;
}
it.remove();

View File

@ -29,10 +29,12 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.provider.OpenableColumns;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -95,7 +97,7 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -108,13 +110,13 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
default:
setTheme(R.style.AppThemeDark);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
@ -126,7 +128,7 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
}
});
toolbar_title.setText(R.string.upload_video);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, PeertubeUploadActivity.this);
}
@ -151,13 +153,12 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IVDEO && resultCode == Activity.RESULT_OK) {
if (data == null || data.getData() == null) {
Toasty.error(getApplicationContext(),getString(R.string.toot_select_image_error),Toast.LENGTH_LONG).show();
Toasty.error(getApplicationContext(), getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
return;
}
set_upload_submit.setEnabled(true);
@ -180,7 +181,7 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
} else if (uriString.startsWith("file://")) {
filename = myFile.getName();
}
if( filename != null) {
if (filename != null) {
set_upload_file_name.setVisibility(View.VISIBLE);
set_upload_file_name.setText(filename);
}
@ -206,8 +207,8 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
@Override
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
if( apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0){
if ( apiResponse.getError() != null && apiResponse.getError().getError() != null)
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
else
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
@ -217,10 +218,10 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
//Populate channels
List<Account> accounts = apiResponse.getAccounts();
String[] channelName = new String[accounts.size()];
String[] channelId= new String[accounts.size()];
String[] channelId = new String[accounts.size()];
int i = 0;
for(Account account: accounts){
channels.put(account.getUsername(),account.getId());
for (Account account : accounts) {
channels.put(account.getUsername(), account.getId());
channelName[i] = account.getUsername();
channelId[i] = account.getId();
i++;
@ -233,11 +234,11 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
set_upload_channel.setAdapter(adapterChannel);
LinkedHashMap<String, String> translations = null;
if( peertubeInformation.getTranslations() != null)
if (peertubeInformation.getTranslations() != null)
translations = new LinkedHashMap<>(peertubeInformation.getTranslations());
LinkedHashMap<Integer, String> privaciesInit = new LinkedHashMap<>(peertubeInformation.getPrivacies());
Map.Entry<Integer,String> entryInt = privaciesInit.entrySet().iterator().next();
Map.Entry<Integer, String> entryInt = privaciesInit.entrySet().iterator().next();
privacyToSend = new HashMap<>();
privacyToSend.put(entryInt.getKey(), entryInt.getValue());
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
@ -246,11 +247,11 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
Iterator it = privacies.entrySet().iterator();
i = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if( translations == null || translations.size() == 0 || !translations.containsKey((String)pair.getValue()))
privaciesA[i] = (String)pair.getValue();
Map.Entry pair = (Map.Entry) it.next();
if (translations == null || translations.size() == 0 || !translations.containsKey((String) pair.getValue()))
privaciesA[i] = (String) pair.getValue();
else
privaciesA[i] = translations.get((String)pair.getValue());
privaciesA[i] = translations.get((String) pair.getValue());
it.remove();
i++;
}
@ -267,10 +268,10 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
Iterator it = privaciesCheck.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if( i == position){
Map.Entry pair = (Map.Entry) it.next();
if (i == position) {
privacyToSend = new HashMap<>();
privacyToSend.put((Integer)pair.getKey(), (String)pair.getValue());
privacyToSend.put((Integer) pair.getKey(), (String) pair.getValue());
break;
}
it.remove();
@ -300,11 +301,11 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
String[] mimetypes = {"video/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, PICK_IVDEO);
}else {
} else {
intent.setType("video/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, PICK_IVDEO);
}
@ -319,10 +320,10 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
Iterator it = channelsCheck.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
if( i == position){
Map.Entry pair = (Map.Entry) it.next();
if (i == position) {
channelToSend = new HashMap<>();
channelToSend.put((String)pair.getKey(), (String)pair.getValue());
channelToSend.put((String) pair.getKey(), (String) pair.getValue());
break;
}
@ -334,7 +335,7 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
set_upload_submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( uri != null) {
if (uri != null) {
Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next();
String idChannel = channelM.getValue();
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
@ -344,7 +345,7 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
Intent in = new Intent(getApplicationContext(), PeertubeEditUploadActivity.class );
Intent in = new Intent(getApplicationContext(), PeertubeEditUploadActivity.class);
PendingIntent clickIntent = PendingIntent.getActivity(getApplicationContext(), 1, in, PendingIntent.FLAG_UPDATE_CURRENT);
uploadConfig
.setClearOnActionForAllStatuses(true);
@ -359,7 +360,7 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
String uploadId = UUID.randomUUID().toString();
uploadReceiver.setUploadID(uploadId);
new MultipartUploadRequest(PeertubeUploadActivity.this, uploadId, "https://" + Helper.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload")
.addFileToUpload(uri.toString().replace("file://",""), "videofile")
.addFileToUpload(uri.toString().replace("file://", ""), "videofile")
.addHeader("Authorization", "Bearer " + token)
.setNotificationConfig(uploadConfig)
.addParameter("name", filename)
@ -370,7 +371,7 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
.addParameter("waitTranscoding", "true")
.setMaxRetries(2)
.startUpload();
finish();
finish();
} catch (Exception exc) {
exc.printStackTrace();
}
@ -380,7 +381,6 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
}
@Override
public void onProgress(Context context, UploadInfo uploadInfo) {
// your code here

View File

@ -18,6 +18,7 @@ import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.exifinterface.media.ExifInterface;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -46,6 +47,7 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.provider.MediaStore;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.transition.ChangeBounds;
@ -53,6 +55,7 @@ import androidx.transition.TransitionManager;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.animation.AnticipateOvershootInterpolator;
import android.widget.Button;
@ -74,7 +77,7 @@ import ja.burhanrashid52.photoeditor.SaveSettings;
import ja.burhanrashid52.photoeditor.ViewType;
public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorListener,
public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorListener,
View.OnClickListener,
PropertiesBSFragment.Properties,
EmojiBSFragment.EmojiListener,
@ -107,7 +110,7 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
requestWindowFeature(Window.FEATURE_NO_TITLE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -122,12 +125,12 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
}
Bundle b = getIntent().getExtras();
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().hide();
String path = null;
if(b != null)
if (b != null)
path = b.getString("imageUri", null);
if( path == null) {
if (path == null) {
finish();
}
uri = Uri.parse(path);
@ -156,7 +159,6 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
mRvFilters.setAdapter(mFilterViewAdapter);
Typeface mEmojiTypeFace = Typeface.createFromAsset(getAssets(), "emojione-android.ttf");
mPhotoEditor = new PhotoEditor.Builder(this, mPhotoEditorView)
@ -165,14 +167,13 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
.build(); // build photo editor sdk
mPhotoEditor.setOnPhotoEditorListener(this);
//Set Image Dynamically
mPhotoEditorView.getSource().setImageURI(uri);
if( uri != null ) {
if (uri != null) {
try (InputStream inputStream = getContentResolver().openInputStream(uri)) {
assert inputStream != null;
ExifInterface exif = new ExifInterface(inputStream);
@ -196,9 +197,13 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
}
private static int exifToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { return 180; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { return 270; }
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {
return 90;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {
return 180;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {
return 270;
}
return 0;
}
@ -306,9 +311,9 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
showLoading(getString(R.string.saving));
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String myDir = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, getCacheDir().getAbsolutePath());
String filename = System.currentTimeMillis()+"_"+Helper.getFileName(PhotoEditorActivity.this, uri);
String filename = System.currentTimeMillis() + "_" + Helper.getFileName(PhotoEditorActivity.this, uri);
File file = new File(myDir+"/"+filename);
File file = new File(myDir + "/" + filename);
try {
file.createNewFile();
@ -323,7 +328,7 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
hideLoading();
showSnackbar(getString(R.string.image_saved));
mPhotoEditorView.getSource().setImageURI(Uri.fromFile(new File(imagePath)));
if( exit ){
if (exit) {
Intent intentImage = new Intent(Helper.INTENT_SEND_MODIFIED_IMAGE);
intentImage.putExtra("imgpath", imagePath);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intentImage);
@ -352,7 +357,7 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
ExifInterface exif = null;
int rotation = 0;
int rotationInDegrees = 0;
if( data != null && data.getData() != null) {
if (data != null && data.getData() != null) {
try (InputStream inputStream = getContentResolver().openInputStream(data.getData())) {
assert inputStream != null;
exif = new androidx.exifinterface.media.ExifInterface(inputStream);
@ -383,15 +388,15 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
case CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE:
CropImage.ActivityResult result = CropImage.getActivityResult(data);
Uri resultUri = result.getUri();
if( resultUri != null) {
if (resultUri != null) {
mPhotoEditorView.getSource().setImageURI(resultUri);
mPhotoEditorView.getSource().setRotation(rotationInDegrees);
File fdelete = new File(uri.getPath());
if (fdelete.exists()) {
fdelete.delete();
fdelete.delete();
}
uri = resultUri;
String filename = System.currentTimeMillis()+"_"+Helper.getFileName(PhotoEditorActivity.this, uri);
String filename = System.currentTimeMillis() + "_" + Helper.getFileName(PhotoEditorActivity.this, uri);
tempname = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(new Date()) + filename;
}
@ -444,13 +449,13 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this, style);
builder.setMessage( getString(R.string.confirm_exit_editing));
builder.setMessage(getString(R.string.confirm_exit_editing));
builder.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@ -519,8 +524,6 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
}
void showFilter(boolean isVisible) {
mIsFilterVisible = isVisible;
mConstraintSet.clone(mRootView);

View File

@ -19,6 +19,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@ -26,6 +27,7 @@ import androidx.appcompat.app.ActionBar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
@ -77,7 +79,7 @@ public class PlaylistsActivity extends BaseActivity implements OnPlaylistActionI
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
break;
@ -90,13 +92,13 @@ public class PlaylistsActivity extends BaseActivity implements OnPlaylistActionI
default:
setTheme(R.style.AppThemeDark_NoActionBar);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
@ -108,24 +110,24 @@ public class PlaylistsActivity extends BaseActivity implements OnPlaylistActionI
}
});
toolbar_title.setText(R.string.upload_video);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, PlaylistsActivity.this);
}
}
setContentView(R.layout.activity_playlists);
Toolbar toolbar = findViewById(R.id.toolbar);
if( theme == Helper.THEME_BLACK)
if (theme == Helper.THEME_BLACK)
toolbar.setBackgroundColor(ContextCompat.getColor(PlaylistsActivity.this, R.color.black));
setSupportActionBar(toolbar);
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
peertubes = new ArrayList<>();
RecyclerView lv_playlist = findViewById(R.id.lv_playlist);
mainLoader = findViewById(R.id.loader);
mainLoader = findViewById(R.id.loader);
nextElementLoader = findViewById(R.id.loading_next_status);
textviewNoAction = findViewById(R.id.no_action);
textviewNoAction = findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE);
swipeRefreshLayout = findViewById(R.id.swipeContainer);
max_id = null;
@ -145,29 +147,28 @@ public class PlaylistsActivity extends BaseActivity implements OnPlaylistActionI
lv_playlist.setLayoutManager(mLayoutManager);
Bundle b = getIntent().getExtras();
if(b != null){
if (b != null) {
playlist = b.getParcelable("playlist");
}else{
Toasty.error(getApplicationContext(),getString(R.string.toast_error_search),Toast.LENGTH_LONG).show();
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
return;
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(playlist.getDisplayName());
lv_playlist.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy)
{
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if(dy > 0){
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
if(!flag_loading ) {
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
new ManagePlaylistsAsyncTask(PlaylistsActivity.this,GET_LIST_VIDEOS, playlist, null, max_id , PlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new ManagePlaylistsAsyncTask(PlaylistsActivity.this, GET_LIST_VIDEOS, playlist, null, max_id, PlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
nextElementLoader.setVisibility(View.VISIBLE);
}
} else {
@ -186,11 +187,11 @@ public class PlaylistsActivity extends BaseActivity implements OnPlaylistActionI
flag_loading = true;
swiped = true;
MainActivity.countNewStatus = 0;
new ManagePlaylistsAsyncTask(PlaylistsActivity.this,GET_LIST_VIDEOS, playlist, null, null , PlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new ManagePlaylistsAsyncTask(PlaylistsActivity.this, GET_LIST_VIDEOS, playlist, null, null, PlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
R.color.mastodonC2,
@ -211,11 +212,10 @@ public class PlaylistsActivity extends BaseActivity implements OnPlaylistActionI
break;
}
new ManagePlaylistsAsyncTask(PlaylistsActivity.this,GET_LIST_VIDEOS, playlist, null, null , PlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new ManagePlaylistsAsyncTask(PlaylistsActivity.this, GET_LIST_VIDEOS, playlist, null, null, PlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -235,14 +235,14 @@ public class PlaylistsActivity extends BaseActivity implements OnPlaylistActionI
nextElementLoader.setVisibility(View.GONE);
//Discards 404 - error which can often happen due to toots which have been deleted
if (apiResponse.getError() != null) {
if ( !apiResponse.getError().getError().startsWith("404 -"))
if (!apiResponse.getError().getError().startsWith("404 -"))
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false);
swiped = false;
flag_loading = false;
return;
}
if( actionType == GET_LIST_VIDEOS) {
if (actionType == GET_LIST_VIDEOS) {
int previousPosition = this.peertubes.size();
List<Peertube> videos = apiResponse.getPeertubes();

View File

@ -18,8 +18,10 @@ package app.fedilab.android.activities;
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
@ -44,7 +46,7 @@ public class PrivacyActivity extends BaseActivity {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -58,13 +60,13 @@ public class PrivacyActivity extends BaseActivity {
setTheme(R.style.AppThemeDark);
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
@ -76,7 +78,7 @@ public class PrivacyActivity extends BaseActivity {
}
});
toolbar_title.setText(R.string.action_privacy);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, PrivacyActivity.this);
}

View File

@ -15,11 +15,12 @@
package app.fedilab.android.activities;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
@ -50,7 +51,7 @@ public class ProxyActivity extends BaseActivity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(ProxyActivity.this, R.color.mastodonC3__));
@ -69,7 +70,7 @@ public class ProxyActivity extends BaseActivity {
}
setContentView(R.layout.activity_proxy);
getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().hide();
//Enable proxy
@ -96,12 +97,12 @@ public class ProxyActivity extends BaseActivity {
int portVal = sharedpreferences.getInt(Helper.SET_PROXY_PORT, 8118);
final String login = sharedpreferences.getString(Helper.SET_PROXY_LOGIN, null);
final String pwd = sharedpreferences.getString(Helper.SET_PROXY_PASSWORD, null);
if( hostVal.length() > 0)
if (hostVal.length() > 0)
host.setText(hostVal);
port.setText(String.valueOf(portVal));
if( login != null && login.length() > 0)
if (login != null && login.length() > 0)
proxy_login.setText(login);
if( pwd != null && proxy_password.length() > 0)
if (pwd != null && proxy_password.length() > 0)
proxy_password.setText(pwd);
count2 = 0;
final Spinner proxy_type = findViewById(R.id.type);
@ -114,14 +115,15 @@ public class ProxyActivity extends BaseActivity {
proxy_type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if( count2 > 0){
if (count2 > 0) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putInt(Helper.SET_PROXY_TYPE, position);
editor.apply();
}else {
} else {
count2++;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
@ -136,7 +138,7 @@ public class ProxyActivity extends BaseActivity {
String proxy_passwordVal = proxy_password.getText().toString().trim();
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.SET_PROXY_HOST, hostVal);
if( portVal.matches("\\d+") )
if (portVal.matches("\\d+"))
editor.putInt(Helper.SET_PROXY_PORT, Integer.parseInt(portVal));
editor.putString(Helper.SET_PROXY_LOGIN, proxy_loginVal);
editor.putString(Helper.SET_PROXY_PASSWORD, proxy_passwordVal);
@ -158,7 +160,4 @@ public class ProxyActivity extends BaseActivity {
}
}

View File

@ -23,12 +23,14 @@ import android.graphics.Paint;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.ItemTouchHelper;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
@ -89,7 +91,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
private RelativeLayout undo_container;
private TextView undo_message;
private TextView undo_action;
private List<ManageTimelines> timelines;
private List<ManageTimelines> timelines;
private ReorderTabAdapter adapter;
private ManageTimelines timeline;
private boolean isLoadingInstance;
@ -102,7 +104,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -120,20 +122,20 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar_add, new LinearLayout(getApplicationContext()), false);
View view = inflater.inflate(R.layout.simple_bar_add, new LinearLayout(getApplicationContext()), false);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
@ -145,9 +147,9 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
finish();
}
});
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
add_remote_instance.setVisibility(View.VISIBLE);
}else{
} else {
add_remote_instance.setVisibility(View.GONE);
}
add_remote_instance.setOnClickListener(new View.OnClickListener() {
@ -168,39 +170,39 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
public void onClick(DialogInterface dialog, int id) {
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String instanceName = instance_list.getText().toString().trim();
new Thread(new Runnable(){
new Thread(new Runnable() {
@Override
public void run() {
try {
if(radioGroup.getCheckedRadioButtonId() == R.id.mastodon_instance)
if (radioGroup.getCheckedRadioButtonId() == R.id.mastodon_instance)
new HttpsConnection(ReorderTimelinesActivity.this, null).get("https://" + instanceName + "/api/v1/timelines/public?local=true", 10, null, null);
else if( radioGroup.getCheckedRadioButtonId() == R.id.peertube_instance)
else if (radioGroup.getCheckedRadioButtonId() == R.id.peertube_instance)
new HttpsConnection(ReorderTimelinesActivity.this, null).get("https://" + instanceName + "/api/v1/videos/", 10, null, null);
else if( radioGroup.getCheckedRadioButtonId() == R.id.pixelfed_instance) {
else if (radioGroup.getCheckedRadioButtonId() == R.id.pixelfed_instance) {
new HttpsConnection(ReorderTimelinesActivity.this, null).get("https://" + instanceName + "/api/v1/timelines/public", 10, null, null);
}else if( radioGroup.getCheckedRadioButtonId() == R.id.misskey_instance) {
} else if (radioGroup.getCheckedRadioButtonId() == R.id.misskey_instance) {
new HttpsConnection(ReorderTimelinesActivity.this, null).post("https://" + instanceName + "/api/notes/local-timeline", 10, null, null);
}else if( radioGroup.getCheckedRadioButtonId() == R.id.gnu_instance) {
} else if (radioGroup.getCheckedRadioButtonId() == R.id.gnu_instance) {
new HttpsConnection(ReorderTimelinesActivity.this, null).get("https://" + instanceName + "/api/statuses/public_timeline.json", 10, null, null);
}
runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
if(radioGroup.getCheckedRadioButtonId() == R.id.mastodon_instance) {
if (radioGroup.getCheckedRadioButtonId() == R.id.mastodon_instance) {
new InstancesDAO(ReorderTimelinesActivity.this, db).insertInstance(instanceName, "MASTODON");
}else if( radioGroup.getCheckedRadioButtonId() == R.id.peertube_instance) {
} else if (radioGroup.getCheckedRadioButtonId() == R.id.peertube_instance) {
new InstancesDAO(ReorderTimelinesActivity.this, db).insertInstance(instanceName, "PEERTUBE");
} else if( radioGroup.getCheckedRadioButtonId() == R.id.pixelfed_instance) {
} else if (radioGroup.getCheckedRadioButtonId() == R.id.pixelfed_instance) {
new InstancesDAO(ReorderTimelinesActivity.this, db).insertInstance(instanceName, "PIXELFED");
} else if( radioGroup.getCheckedRadioButtonId() == R.id.misskey_instance) {
} else if (radioGroup.getCheckedRadioButtonId() == R.id.misskey_instance) {
new InstancesDAO(ReorderTimelinesActivity.this, db).insertInstance(instanceName, "MISSKEY");
}else if( radioGroup.getCheckedRadioButtonId() == R.id.gnu_instance) {
} else if (radioGroup.getCheckedRadioButtonId() == R.id.gnu_instance) {
new InstancesDAO(ReorderTimelinesActivity.this, db).insertInstance(instanceName, "GNU");
}
if( timelines != null && adapter != null) {
if (timelines != null && adapter != null) {
List<RemoteInstance> instance = new InstancesDAO(ReorderTimelinesActivity.this, db).getInstanceByName(instanceName);
if( instance != null && instance.size() > 0 ) {
if (instance != null && instance.size() > 0) {
ManageTimelines manageTimelines = new ManageTimelines();
manageTimelines.setRemoteInstance(instance.get(0));
manageTimelines.setPosition(timelines.size());
@ -235,13 +237,13 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
imm.hideSoftInputFromWindow(instance_list.getWindowToken(), 0);
}
});
if( alertDialog.getWindow() != null )
if (alertDialog.getWindow() != null)
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
instance_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String oldSearch = parent.getItemAtPosition(position).toString().trim();
}
});
@ -259,7 +261,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
public void afterTextChanged(Editable s) {
Pattern host = Pattern.compile("([\\da-z\\.-]+\\.[a-z\\.]{2,12})");
Matcher matcher = host.matcher(s.toString().trim());
if( s.toString().trim().length() == 0 || !matcher.find()) {
if (s.toString().trim().length() == 0 || !matcher.find()) {
alertDialog.getButton(
AlertDialog.BUTTON_POSITIVE).setEnabled(false);
} else {
@ -275,7 +277,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
parameters.put("name", String.valueOf(true));
isLoadingInstance = true;
if( oldSearch == null || !oldSearch.equals(s.toString().trim()))
if (oldSearch == null || !oldSearch.equals(s.toString().trim()))
new Thread(new Runnable() {
@Override
public void run() {
@ -291,13 +293,13 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
if (jsonArray != null) {
int length = 0;
for (int i = 0; i < jsonArray.length(); i++) {
if( !jsonArray.getJSONObject(i).get("name").toString().contains("@") && jsonArray.getJSONObject(i).get("up").toString().equals("true"))
if (!jsonArray.getJSONObject(i).get("name").toString().contains("@") && jsonArray.getJSONObject(i).get("up").toString().equals("true"))
length++;
}
instances = new String[length];
int j = 0;
for (int i = 0; i < jsonArray.length(); i++) {
if( !jsonArray.getJSONObject(i).get("name").toString().contains("@") && jsonArray.getJSONObject(i).get("up").toString().equals("true")) {
if (!jsonArray.getJSONObject(i).get("name").toString().contains("@") && jsonArray.getJSONObject(i).get("up").toString().equals("true")) {
instances[j] = jsonArray.getJSONObject(i).get("name").toString();
j++;
}
@ -334,7 +336,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
}
});
toolbar_title.setText(R.string.action_reorder_timeline);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, ReorderTimelinesActivity.this);
}
@ -342,7 +344,6 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
setContentView(R.layout.activity_reorder_tabs);
updated = false;
RecyclerView lv_reorder_tabs = findViewById(R.id.lv_reorder_tabs);
@ -373,7 +374,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
if (theme == Helper.THEME_LIGHT)
undo_container.setBackgroundColor(getResources().getColor(R.color.mastodonC3));
undo_container.setVisibility(View.VISIBLE);
switch (manageTimelines.getType()){
switch (manageTimelines.getType()) {
case TAG:
undo_message.setText(R.string.reorder_tag_removed);
break;
@ -390,7 +391,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
public void run() {
undo_container.setVisibility(View.GONE);
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
switch (manageTimelines.getType()){
switch (manageTimelines.getType()) {
case TAG:
new SearchDAO(getApplicationContext(), db).remove(manageTimelines.getTagTimeline().getName());
new TimelinesDAO(getApplicationContext(), db).remove(manageTimelines);
@ -401,7 +402,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
break;
case LIST:
timeline = manageTimelines;
new ManageListsAsyncTask(getApplicationContext(), ManageListsAsyncTask.action.DELETE_LIST,null, null, manageTimelines.getListTimeline().getId(), null, ReorderTimelinesActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new ManageListsAsyncTask(getApplicationContext(), ManageListsAsyncTask.action.DELETE_LIST, null, null, manageTimelines.getListTimeline().getId(), null, ReorderTimelinesActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new TimelinesDAO(getApplicationContext(), db).remove(timeline);
break;
}
@ -422,9 +423,9 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
}
@Override
public void onStop(){
public void onStop() {
super.onStop();
if( updated ) {
if (updated) {
Intent intent = new Intent(getBaseContext(), MainActivity.class);
intent.putExtra(Helper.INTENT_ACTION, Helper.REFRESH_TIMELINE);
startActivity(intent);

View File

@ -18,8 +18,10 @@ import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
@ -64,7 +66,7 @@ public class SearchResultActivity extends BaseActivity implements OnRetrieveSear
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -84,22 +86,22 @@ public class SearchResultActivity extends BaseActivity implements OnRetrieveSear
lv_search = findViewById(R.id.lv_search);
Bundle b = getIntent().getExtras();
if(b != null){
if (b != null) {
search = b.getString("search");
if( search != null)
if (search != null)
new RetrieveSearchAsyncTask(getApplicationContext(), search.trim(), SearchResultActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else
Toasty.error(getApplicationContext(),getString(R.string.toast_error_search),Toast.LENGTH_LONG).show();
}else{
Toasty.error(getApplicationContext(),getString(R.string.toast_error_search),Toast.LENGTH_LONG).show();
Toasty.error(getApplicationContext(), getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
@ -111,7 +113,7 @@ public class SearchResultActivity extends BaseActivity implements OnRetrieveSear
}
});
toolbar_title.setText(search);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, SearchResultActivity.this);
}
@ -138,22 +140,22 @@ public class SearchResultActivity extends BaseActivity implements OnRetrieveSear
@Override
public void onRetrieveSearch(APIResponse apiResponse) {
loader.setVisibility(View.GONE);
if( apiResponse.getError() != null){
if( apiResponse.getError().getError() != null)
Toasty.error(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
if (apiResponse.getError() != null) {
if (apiResponse.getError().getError() != null)
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
else
Toasty.error(getApplicationContext(), getString(R.string.toast_error),Toast.LENGTH_LONG).show();
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
if( apiResponse.getResults() == null || ( apiResponse.getResults().getAccounts().size() == 0 && apiResponse.getResults().getStatuses().size() == 0 && apiResponse.getResults().getHashtags().size() == 0)){
if (apiResponse.getResults() == null || (apiResponse.getResults().getAccounts().size() == 0 && apiResponse.getResults().getStatuses().size() == 0 && apiResponse.getResults().getHashtags().size() == 0)) {
RelativeLayout no_result = findViewById(R.id.no_result);
no_result.setVisibility(View.VISIBLE);
return;
}
lv_search.setVisibility(View.VISIBLE);
List<String> tags = apiResponse.getResults().getHashtags();
List<Account> accounts = apiResponse.getResults().getAccounts();
List<Status> statuses = apiResponse.getResults().getStatuses();
List<String> tags = apiResponse.getResults().getHashtags();
List<Account> accounts = apiResponse.getResults().getAccounts();
List<Status> statuses = apiResponse.getResults().getStatuses();
SearchListAdapter searchListAdapter = new SearchListAdapter(SearchResultActivity.this, statuses, accounts, tags);
lv_search.setAdapter(searchListAdapter);
@ -165,8 +167,8 @@ public class SearchResultActivity extends BaseActivity implements OnRetrieveSear
@Override
public void onRetrieveSearchStatus(APIResponse apiResponse, Error error) {
loader.setVisibility(View.GONE);
if( apiResponse.getError() != null){
Toasty.error(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();
if (apiResponse.getError() != null) {
Toasty.error(getApplicationContext(), error.getError(), Toast.LENGTH_LONG).show();
return;
}
lv_search.setVisibility(View.VISIBLE);

View File

@ -17,7 +17,9 @@ package app.fedilab.android.activities;
import android.content.SharedPreferences;
import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
@ -25,6 +27,7 @@ import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
@ -51,7 +54,7 @@ import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
* Show search results within tabs
*/
public class SearchResultTabActivity extends BaseActivity {
public class SearchResultTabActivity extends BaseActivity {
private String search;
@ -64,7 +67,7 @@ public class SearchResultTabActivity extends BaseActivity {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -82,27 +85,27 @@ public class SearchResultTabActivity extends BaseActivity {
Bundle b = getIntent().getExtras();
if(b != null){
if (b != null) {
search = b.getString("search");
if( search == null)
Toasty.error(getApplicationContext(),getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
}else{
Toasty.error(getApplicationContext(),getString(R.string.toast_error_search),Toast.LENGTH_LONG).show();
if (search == null)
Toasty.error(getApplicationContext(), getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
}
if( search == null)
if (search == null)
finish();
tabLayout = findViewById(R.id.search_tabLayout);
search_viewpager = findViewById(R.id.search_viewpager);
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
@ -114,7 +117,7 @@ public class SearchResultTabActivity extends BaseActivity {
}
});
toolbar_title.setText(search);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, SearchResultTabActivity.this);
}
@ -137,7 +140,7 @@ public class SearchResultTabActivity extends BaseActivity {
@Override
public void onPageSelected(int position) {
TabLayout.Tab tab = tabLayout.getTabAt(position);
if( tab != null)
if (tab != null)
tab.select();
}
@ -161,7 +164,7 @@ public class SearchResultTabActivity extends BaseActivity {
@Override
public void onTabReselected(TabLayout.Tab tab) {
Fragment fragment;
if( search_viewpager.getAdapter() != null) {
if (search_viewpager.getAdapter() != null) {
fragment = (Fragment) search_viewpager.getAdapter().instantiateItem(search_viewpager, tab.getPosition());
if (fragment instanceof DisplayAccountsFragment) {
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
@ -202,7 +205,7 @@ public class SearchResultTabActivity extends BaseActivity {
@Override
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
switch (position){
switch (position) {
case 0:
DisplaySearchTagsFragment displaySearchTagsFragment = new DisplaySearchTagsFragment();
displaySearchTagsFragment.setArguments(bundle);

View File

@ -66,12 +66,13 @@ public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewA
private List<SlideMenuItem> list = new ArrayList<>();
public static int position = 1;
private ContentSettingsFragment.type previous;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
break;
@ -85,13 +86,13 @@ public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewA
setTheme(R.style.AppThemeDark_NoActionBar);
}
position = 1;
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
@ -103,7 +104,7 @@ public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewA
}
});
toolbar_title.setText(R.string.action_about);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, SettingsActivity.this);
}
@ -170,7 +171,7 @@ public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewA
}
@Override
public void onDestroy(){
public void onDestroy() {
super.onDestroy();
}
@ -191,7 +192,7 @@ public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewA
list.add(menuItemInterface);
list.add(menuItemBattery);
list.add(menuItemEdit);
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
list.add(menuMenu);
list.add(menuItemAdmin);
}
@ -211,9 +212,6 @@ public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewA
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
@ -224,10 +222,8 @@ public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewA
}
@Override
public void onResume(){
public void onResume() {
super.onResume();
}
@ -235,11 +231,11 @@ public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewA
private ScreenShotable replaceFragment(ScreenShotable screenShotable, ContentSettingsFragment.type type, int topPosition) {
this.res = this.res == R.drawable.ic_timeline_menu_s ? R.drawable.ic_notifications_menu : R.drawable.ic_timeline_menu_s;
if( type == ContentSettingsFragment.type.LANGUAGE){
if (type == ContentSettingsFragment.type.LANGUAGE) {
Intent intent = new Intent(getApplicationContext(), LanguageActivity.class);
startActivity(intent);
type = previous;
}else if( type == ContentSettingsFragment.type.MENU){
} else if (type == ContentSettingsFragment.type.MENU) {
Intent intent = new Intent(getApplicationContext(), HideItemActivity.class);
startActivity(intent);
type = previous;

View File

@ -23,6 +23,7 @@ import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@ -64,7 +65,7 @@ import app.fedilab.android.interfaces.OnRetrieveContextInterface;
* Show conversation activity class
*/
public class ShowConversationActivity extends BaseActivity implements OnRetrieveContextInterface {
public class ShowConversationActivity extends BaseActivity implements OnRetrieveContextInterface {
private Status initialStatus;
@ -85,7 +86,7 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
break;
@ -102,27 +103,27 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
setContentView(R.layout.activity_show_conversation);
lv_status = findViewById(R.id.lv_status);
Toolbar toolbar = findViewById(R.id.toolbar);
if( theme == Helper.THEME_BLACK)
if (theme == Helper.THEME_BLACK)
toolbar.setBackgroundColor(ContextCompat.getColor(ShowConversationActivity.this, R.color.black));
setSupportActionBar(toolbar);
spoilerShown = spoilerBehaviour =sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false);
spoilerShown = spoilerBehaviour = sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false);
Bundle b = getIntent().getExtras();
statuses = new ArrayList<>();
if(b != null) {
if (b != null) {
detailsStatus = b.getParcelable("status");
expanded = b.getBoolean("expanded", false);
expanded = b.getBoolean("expanded", false);
initialStatus = b.getParcelable("initialStatus");
conversationId = b.getString("conversationId", null);
conversationId = b.getString("conversationId", null);
}
if( detailsStatus == null || detailsStatus.getId() == null)
if (detailsStatus == null || detailsStatus.getId() == null)
finish();
detailsStatus.setFocused(true);
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
if( receive_action != null)
if (receive_action != null)
LocalBroadcastManager.getInstance(getApplicationContext()).unregisterReceiver(receive_action);
receive_action = new BroadcastReceiver() {
@Override
@ -130,7 +131,7 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
Bundle b = intent.getExtras();
assert b != null;
Status status = b.getParcelable("status");
if( status != null && statusListAdapter != null) {
if (status != null && statusListAdapter != null) {
statusListAdapter.notifyStatusWithActionChanged(status);
}
}
@ -138,12 +139,12 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_ACTION));
}
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if( getSupportActionBar() != null) {
if (getSupportActionBar() != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.conversation_action_bar, new LinearLayout(getApplicationContext()), false);
View view = inflater.inflate(R.layout.conversation_action_bar, new LinearLayout(getApplicationContext()), false);
getSupportActionBar().setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
TextView title = getSupportActionBar().getCustomView().findViewById(R.id.toolbar_title);
@ -153,19 +154,19 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
title.setText(R.string.conversation);
ImageView close_conversation = getSupportActionBar().getCustomView().findViewById(R.id.close_conversation);
ImageView action_unhide = getSupportActionBar().getCustomView().findViewById(R.id.action_unhide);
if( expanded)
if (expanded)
action_expand.setImageResource(R.drawable.ic_expand_less);
else
action_expand.setImageResource(R.drawable.ic_expand_more);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if( lv_status != null) {
if (lv_status != null) {
lv_status.setAdapter(statusListAdapter);
}
}
});
if( close_conversation != null){
if (close_conversation != null) {
close_conversation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -180,7 +181,7 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
Bundle b = new Bundle();
b.putParcelable("status", detailsStatus);
b.putBoolean("expanded", expanded);
if( expanded && statuses != null && statuses.size() > 0)
if (expanded && statuses != null && statuses.size() > 0)
b.putParcelable("initialStatus", statuses.get(0));
intent.putExtras(b);
finish();
@ -191,12 +192,12 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
action_unhide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( statuses != null && statuses.size() > 0) {
if (statuses != null && statuses.size() > 0) {
spoilerShown = !spoilerShown;
for (Status status : statuses) {
if( spoilerBehaviour && !status.isSpoilerShown() ){
if (spoilerBehaviour && !status.isSpoilerShown()) {
status.setAutoHiddenCW(true);
}else{
} else {
status.setAutoHiddenCW(false);
}
status.setSpoilerShown(spoilerShown);
@ -215,7 +216,7 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
Bundle b = new Bundle();
b.putParcelable("status", detailsStatus);
b.putBoolean("expanded", expanded);
if( expanded && statuses != null && statuses.size() > 0)
if (expanded && statuses != null && statuses.size() > 0)
b.putParcelable("initialStatus", statuses.get(0));
intent.putExtras(b);
finish();
@ -225,19 +226,19 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
}
});
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Helper.colorizeToolbar(getSupportActionBar().getCustomView().findViewById(R.id.toolbar), R.color.black, ShowConversationActivity.this);
}
}else{
} else {
setTitle(R.string.conversation);
}
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
Account account = new AccountDAO(getApplicationContext(),db).getUniqAccount(userId, instance);
if( account.getAvatar() == null){
Toasty.error(getApplicationContext(),getString(R.string.toast_error), Toast.LENGTH_LONG).show();
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
if (account.getAvatar() == null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
finish();
}
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
@ -245,7 +246,7 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
swipeRefreshLayout = findViewById(R.id.swipeContainer);
boolean isOnWifi = Helper.isOnWIFI(getApplicationContext());
if( initialStatus != null)
if (initialStatus != null)
statuses.add(initialStatus);
else
statuses.add(detailsStatus);
@ -257,17 +258,17 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
lv_status.addItemDecoration(new ConversationDecoration(ShowConversationActivity.this, theme));
lv_status.setAdapter(statusListAdapter);
String statusIdToFetch = null;
if( initialStatus != null)
if (initialStatus != null)
statusIdToFetch = initialStatus.getId();
else if(detailsStatus != null)
else if (detailsStatus != null)
statusIdToFetch = detailsStatus.getId();
if( statusIdToFetch == null)
if (statusIdToFetch == null)
finish();
if( conversationId != null)
if (conversationId != null)
statusIdToFetch = conversationId;
new RetrieveContextAsyncTask(getApplicationContext(),expanded, detailsStatus.getVisibility().equals("direct"), statusIdToFetch, ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
switch (theme){
new RetrieveContextAsyncTask(getApplicationContext(), expanded, detailsStatus.getVisibility().equals("direct"), statusIdToFetch, ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
switch (theme) {
case Helper.THEME_LIGHT:
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
R.color.mastodonC2,
@ -295,7 +296,7 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
Bundle b = new Bundle();
b.putParcelable("status", detailsStatus);
b.putBoolean("expanded", expanded);
if( expanded && statuses != null && statuses.size() > 0)
if (expanded && statuses != null && statuses.size() > 0)
b.putParcelable("initialStatus", statuses.get(0));
b.putParcelable("status", detailsStatus);
intent.putExtras(b);
@ -308,13 +309,13 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
}
public void addStatuses(Status status){
if( status != null && status.getIn_reply_to_id() != null && this.statuses != null){
public void addStatuses(Status status) {
if (status != null && status.getIn_reply_to_id() != null && this.statuses != null) {
int position = 0;
for(Status s: this.statuses){
if(status.getIn_reply_to_id().equals(s.getId())){
this.statuses.add(position+1, status);
statusListAdapter.notifyItemInserted(position+1);
for (Status s : this.statuses) {
if (status.getIn_reply_to_id().equals(s.getId())) {
this.statuses.add(position + 1, status);
statusListAdapter.notifyItemInserted(position + 1);
break;
}
position++;
@ -336,70 +337,70 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
@Override
public void onDestroy() {
super.onDestroy();
if( receive_action != null)
if (receive_action != null)
LocalBroadcastManager.getInstance(getApplicationContext()).unregisterReceiver(receive_action);
}
@Override
public void onRetrieveContext(Context context, Error error) {
swipeRefreshLayout.setRefreshing(false);
if( error != null ){
Toasty.error(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();
if (error != null) {
Toasty.error(getApplicationContext(), error.getError(), Toast.LENGTH_LONG).show();
return;
}
if( context.getAncestors() == null ){
if (context.getAncestors() == null) {
return;
}
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
statusListAdapter.setConversationPosition( context.getAncestors().size());
if(!expanded) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
statusListAdapter.setConversationPosition(context.getAncestors().size());
if (!expanded) {
if (context.getAncestors() != null && context.getAncestors().size() > 0) {
statuses.addAll(0, context.getAncestors());
statusListAdapter.notifyItemRangeInserted(0, context.getAncestors().size());
}
if (context.getDescendants() != null && context.getDescendants().size() > 0) {
statuses.addAll(context.getAncestors().size() + 1, context.getDescendants());
statusListAdapter.notifyItemRangeChanged(context.getAncestors().size()+1, context.getDescendants().size());
statusListAdapter.notifyItemRangeChanged(context.getAncestors().size() + 1, context.getDescendants().size());
}
}else{
} else {
List<Status> statusesTemp = context.getDescendants();
int i = 1;
int position = 0;
for(Status status: statusesTemp){
for (Status status : statusesTemp) {
statuses.add(status);
if( status.getId().equals(detailsStatus.getId())) {
if (status.getId().equals(detailsStatus.getId())) {
statusListAdapter.setConversationPosition(i);
detailsStatus = status;
position = i;
}
i++;
}
statusListAdapter.notifyItemRangeChanged(1,context.getDescendants().size());
statusListAdapter.notifyItemRangeChanged(1, context.getDescendants().size());
lv_status.scrollToPosition(position);
}
}else{
} else {
int i = 0;
if( context.getAncestors() != null && context.getAncestors().size() > 1){
if (context.getAncestors() != null && context.getAncestors().size() > 1) {
statuses = new ArrayList<>();
statuses.clear();
for(Status status: context.getAncestors()){
if(detailsStatus.equals(status)) {
for (Status status : context.getAncestors()) {
if (detailsStatus.equals(status)) {
break;
}
i++;
}
boolean isOnWifi = Helper.isOnWIFI(getApplicationContext());
for(Status status: context.getAncestors()){
statuses.add(0,status);
for (Status status : context.getAncestors()) {
statuses.add(0, status);
}
statusListAdapter = new StatusListAdapter((statuses.size()-1-i), null, isOnWifi, statuses);
statusListAdapter.setConversationPosition((statuses.size()-1-i));
statusListAdapter = new StatusListAdapter((statuses.size() - 1 - i), null, isOnWifi, statuses);
statusListAdapter.setConversationPosition((statuses.size() - 1 - i));
final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(this);
lv_status.setLayoutManager(mLayoutManager);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
break;

View File

@ -19,9 +19,11 @@ import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
@ -58,7 +60,7 @@ public class TagCacheActivity extends BaseActivity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(TagCacheActivity.this, R.color.mastodonC3__));
@ -88,10 +90,10 @@ public class TagCacheActivity extends BaseActivity {
save_tag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( tag_add.getText() != null && tag_add.getText().toString().trim().replaceAll("\\#","").length() > 0) {
String tagToInsert = tag_add.getText().toString().trim().replaceAll("\\#","");
if (tag_add.getText() != null && tag_add.getText().toString().trim().replaceAll("\\#", "").length() > 0) {
String tagToInsert = tag_add.getText().toString().trim().replaceAll("\\#", "");
boolean isPresent = new TagsCacheDAO(TagCacheActivity.this, db).isPresent(tagToInsert);
if( isPresent)
if (isPresent)
Toasty.warning(TagCacheActivity.this, getString(R.string.tags_already_stored), Toast.LENGTH_LONG).show();
else {
new TagsCacheDAO(TagCacheActivity.this, db).insert(tagToInsert);
@ -111,9 +113,9 @@ public class TagCacheActivity extends BaseActivity {
public void run() {
List<String> tagsTemp = new TagsCacheDAO(TagCacheActivity.this, db).getAll();
if( tagsTemp != null)
if (tagsTemp != null)
tags = tagsTemp;
if( tags != null){
if (tags != null) {
tagsEditAdapter = new TagsEditAdapter(tags);
tag_list.setAdapter(tagsEditAdapter);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(TagCacheActivity.this);

View File

@ -17,12 +17,15 @@ package app.fedilab.android.activities;
import android.content.SharedPreferences;
import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Toast;
@ -55,7 +58,7 @@ public class TootInfoActivity extends BaseActivity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -71,24 +74,24 @@ public class TootInfoActivity extends BaseActivity {
setContentView(R.layout.activity_toot_info);
getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
Bundle b = getIntent().getExtras();
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().hide();
int toot_reblogs_count = 0;
int toot_favorites_count = 0;
if( b != null){
if (b != null) {
toot_id = b.getString("toot_id", null);
toot_reblogs_count = b.getInt("toot_reblogs_count", 0);
toot_favorites_count = b.getInt("toot_favorites_count", 0);
}
if( toot_id == null){
if (toot_id == null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_SHORT).show();
finish();
}
userID = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
tabLayout = findViewById(R.id.tabLayout);
mPager = findViewById(R.id.viewpager);
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.reblog) + " ("+toot_reblogs_count+")"));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.favourite) + " ("+toot_favorites_count+")"));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.reblog) + " (" + toot_reblogs_count + ")"));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.favourite) + " (" + toot_favorites_count + ")"));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@ -96,6 +99,7 @@ public class TootInfoActivity extends BaseActivity {
public void onTabSelected(TabLayout.Tab tab) {
mPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
@ -118,7 +122,7 @@ public class TootInfoActivity extends BaseActivity {
@Override
public void onPageSelected(int position) {
TabLayout.Tab tab = tabLayout.getTabAt(position);
if( tab != null)
if (tab != null)
tab.select();
}
@ -130,12 +134,12 @@ public class TootInfoActivity extends BaseActivity {
}
public void updateBoostCount(int count){
Objects.requireNonNull(tabLayout.getTabAt(0)).setText(getString(R.string.reblog) + " ("+count+")");
public void updateBoostCount(int count) {
Objects.requireNonNull(tabLayout.getTabAt(0)).setText(getString(R.string.reblog) + " (" + count + ")");
}
public void updateFavCount(int count){
Objects.requireNonNull(tabLayout.getTabAt(1)).setText(getString(R.string.favourite) + " ("+count+")");
public void updateFavCount(int count) {
Objects.requireNonNull(tabLayout.getTabAt(1)).setText(getString(R.string.favourite) + " (" + count + ")");
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
@ -147,7 +151,7 @@ public class TootInfoActivity extends BaseActivity {
@Override
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
switch (position){
switch (position) {
case 0:
DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment();
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.REBLOGGED);

View File

@ -29,9 +29,11 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AlertDialog;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -80,7 +82,7 @@ public class WebviewActivity extends BaseActivity {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -97,14 +99,14 @@ public class WebviewActivity extends BaseActivity {
setContentView(R.layout.activity_webview);
Bundle b = getIntent().getExtras();
if(b != null) {
if (b != null) {
url = b.getString("url", null);
peertubeLinkToFetch = b.getString("peertubeLinkToFetch", null);
peertubeLink = b.getBoolean("peertubeLink", false);
peertubeLink = b.getBoolean("peertubeLink", false);
}
if( url == null)
if (url == null)
finish();
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
webView = Helper.initializeWebview(WebviewActivity.this, R.id.webview);
@ -115,13 +117,13 @@ public class WebviewActivity extends BaseActivity {
boolean proxyEnabled = sharedpreferences.getBoolean(Helper.SET_PROXY_ENABLED, false);
if( proxyEnabled ){
if (proxyEnabled) {
String host = sharedpreferences.getString(Helper.SET_PROXY_HOST, "127.0.0.1");
int port = sharedpreferences.getInt(Helper.SET_PROXY_PORT, 8118);
ProxyHelper.setProxy(getApplicationContext(), webView,host, port,WebviewActivity.class.getName());
ProxyHelper.setProxy(getApplicationContext(), webView, host, port, WebviewActivity.class.getName());
}
MastalabWebChromeClient mastalabWebChromeClient = new MastalabWebChromeClient(WebviewActivity.this, webView, webview_container, videoLayout);
MastalabWebChromeClient mastalabWebChromeClient = new MastalabWebChromeClient(WebviewActivity.this, webView, webview_container, videoLayout);
mastalabWebChromeClient.setOnToggledFullscreen(new MastalabWebChromeClient.ToggledFullscreenCallback() {
@Override
public void toggledFullscreen(boolean fullscreen) {
@ -150,26 +152,26 @@ public class WebviewActivity extends BaseActivity {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
if(Build.VERSION.SDK_INT >= 23 ){
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{
} else {
Helper.manageDownloads(WebviewActivity.this, url);
}
}
});
if( !url.startsWith("http://") && !url.startsWith("https://"))
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
if( trackingDomains == null){
if (trackingDomains == null) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
SQLiteDatabase db = Sqlite.getInstance(WebviewActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
trackingDomains = new DomainBlockDAO(WebviewActivity.this, db).getAll();
if( trackingDomains == null)
if (trackingDomains == null)
trackingDomains = new ArrayList<>();
// Get a handler that can be used to post to the main thread
Handler mainHandler = new Handler(getMainLooper());
@ -183,13 +185,13 @@ public class WebviewActivity extends BaseActivity {
}
});
}else
} else
webView.loadUrl(url);
}
public void setCount(Context context, String count) {
if( defaultMenu != null && !peertubeLink) {
if (defaultMenu != null && !peertubeLink) {
MenuItem menuItem = defaultMenu.findItem(R.id.action_block);
LayerDrawable icon = (LayerDrawable) menuItem.getIcon();
@ -211,7 +213,7 @@ public class WebviewActivity extends BaseActivity {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if(!peertubeLink)
if (!peertubeLink)
setCount(this, "0");
defaultMenu = menu;
return super.onPrepareOptionsMenu(menu);
@ -221,17 +223,18 @@ public class WebviewActivity extends BaseActivity {
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_webview, menu);
defaultMenu = menu;
if( peertubeLink ){
if (peertubeLink) {
menu.findItem(R.id.action_go).setVisible(false);
menu.findItem(R.id.action_block).setVisible(false);
menu.findItem(R.id.action_comment).setVisible(true);
}
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_LIGHT)
if (theme == Helper.THEME_LIGHT)
Helper.colorizeIconMenu(menu, R.color.black);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -249,9 +252,9 @@ public class WebviewActivity extends BaseActivity {
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
}else {
} else {
style = R.style.Dialog;
}
AlertDialog.Builder builder = new AlertDialog.Builder(WebviewActivity.this, style);
@ -279,8 +282,8 @@ public class WebviewActivity extends BaseActivity {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
try {
startActivity(browserIntent);
}catch (Exception e){
Toasty.error(getApplicationContext(),getString(R.string.toast_error),Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
return true;
case R.id.action_comment:
@ -293,7 +296,7 @@ public class WebviewActivity extends BaseActivity {
@Override
protected Void doInBackground(Void... voids) {
if(url != null) {
if (url != null) {
APIResponse search = new API(contextReference.get()).search(peertubeLinkToFetch);
if (search != null && search.getResults() != null) {
remoteStatuses = search.getResults().getStatuses();
@ -306,46 +309,46 @@ public class WebviewActivity extends BaseActivity {
protected void onPostExecute(Void result) {
Intent intent = new Intent(contextReference.get(), TootActivity.class);
Bundle b = new Bundle();
if( remoteStatuses == null || remoteStatuses.size() == 0){
Toasty.error(contextReference.get(),getString(R.string.toast_error),Toast.LENGTH_LONG).show();
if (remoteStatuses == null || remoteStatuses.size() == 0) {
Toasty.error(contextReference.get(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
if( remoteStatuses.get(0).getReblog() != null ) {
if (remoteStatuses.get(0).getReblog() != null) {
b.putParcelable("tootReply", remoteStatuses.get(0).getReblog());
}else {
} else {
b.putParcelable("tootReply", remoteStatuses.get(0));
}
intent.putExtras(b); //Put your id to your next Intent
contextReference.get().startActivity(intent);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR );
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void setUrl(String newUrl){
public void setUrl(String newUrl) {
this.url = newUrl;
}
@Override
public void onPause(){
public void onPause() {
super.onPause();
if( webView != null)
if (webView != null)
webView.onPause();
}
@Override
public void onResume(){
public void onResume() {
super.onResume();
if( webView != null)
if (webView != null)
webView.onResume();
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
@ -353,9 +356,9 @@ public class WebviewActivity extends BaseActivity {
}
@Override
public void onDestroy(){
public void onDestroy() {
super.onDestroy();
if( webView != null)
if (webView != null)
webView.destroy();
}
}

View File

@ -23,9 +23,11 @@ import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -69,7 +71,7 @@ public class WebviewConnectActivity extends BaseActivity {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
@ -85,19 +87,19 @@ public class WebviewConnectActivity extends BaseActivity {
setContentView(R.layout.activity_webview_connect);
Bundle b = getIntent().getExtras();
if(b != null) {
if (b != null) {
instance = b.getString("instance");
social = (UpdateAccountInfoAsyncTask.SOCIAL) b.getSerializable("social");
}
if( instance == null)
if (instance == null)
finish();
clientId = sharedpreferences.getString(Helper.CLIENT_ID, null);
clientSecret = sharedpreferences.getString(Helper.CLIENT_SECRET, null);
ActionBar actionBar = getSupportActionBar();
if( actionBar != null ) {
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
@ -109,7 +111,7 @@ public class WebviewConnectActivity extends BaseActivity {
}
});
toolbar_title.setText(R.string.add_account);
if (theme == Helper.THEME_LIGHT){
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, WebviewConnectActivity.this);
}
@ -139,20 +141,20 @@ public class WebviewConnectActivity extends BaseActivity {
});
boolean proxyEnabled = sharedpreferences.getBoolean(Helper.SET_PROXY_ENABLED, false);
if( proxyEnabled ){
if (proxyEnabled) {
String host = sharedpreferences.getString(Helper.SET_PROXY_HOST, "127.0.0.1");
int port = sharedpreferences.getInt(Helper.SET_PROXY_PORT, 8118);
ProxyHelper.setProxy(getApplicationContext(), webView,host, port,WebviewConnectActivity.class.getName());
ProxyHelper.setProxy(getApplicationContext(), webView, host, port, WebviewConnectActivity.class.getName());
}
webView.setWebViewClient(new WebViewClient() {
@SuppressWarnings("deprecation")
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
super.shouldOverrideUrlLoading(view,url);
if( url.contains(Helper.REDIRECT_CONTENT_WEB)){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
super.shouldOverrideUrlLoading(view, url);
if (url.contains(Helper.REDIRECT_CONTENT_WEB)) {
String val[] = url.split("code=");
if (val.length< 2){
if (val.length < 2) {
Toasty.error(getApplicationContext(), getString(R.string.toast_code_error), Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(WebviewConnectActivity.this, LoginActivity.class);
startActivity(myIntent);
@ -164,10 +166,10 @@ public class WebviewConnectActivity extends BaseActivity {
final HashMap<String, String> parameters = new HashMap<>();
parameters.put(Helper.CLIENT_ID, clientId);
parameters.put(Helper.CLIENT_SECRET, clientSecret);
parameters.put(Helper.REDIRECT_URI,Helper.REDIRECT_CONTENT_WEB);
parameters.put(Helper.REDIRECT_URI, Helper.REDIRECT_CONTENT_WEB);
parameters.put("grant_type", "authorization_code");
parameters.put("code",code);
new Thread(new Runnable(){
parameters.put("code", code);
new Thread(new Runnable() {
@Override
public void run() {
try {
@ -177,7 +179,7 @@ public class WebviewConnectActivity extends BaseActivity {
resobj = new JSONObject(response);
String token = resobj.get("access_token").toString();
String refresh_token = null;
if( resobj.has("refresh_token"))
if (resobj.has("refresh_token"))
refresh_token = resobj.get("refresh_token").toString();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
@ -185,9 +187,12 @@ public class WebviewConnectActivity extends BaseActivity {
editor.apply();
//Update the account with the token;
new UpdateAccountInfoAsyncTask(WebviewConnectActivity.this, token, clientId, clientSecret, refresh_token, instance, social).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (JSONException ignored) {}
} catch (Exception ignored) {}
}}).start();
} catch (JSONException ignored) {
}
} catch (Exception ignored) {
}
}
}).start();
return true;
}
return false;
@ -208,8 +213,6 @@ public class WebviewConnectActivity extends BaseActivity {
}
@Override
public void onDestroy() {
super.onDestroy();
@ -220,16 +223,15 @@ public class WebviewConnectActivity extends BaseActivity {
}
@SuppressWarnings("deprecation")
public static void clearCookies(Context context)
{
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);
CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
cookieSyncMngr.startSync();
CookieManager cookieManager=CookieManager.getInstance();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
cookieManager.removeSessionCookie();
cookieSyncMngr.stopSync();

View File

@ -19,8 +19,10 @@ import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.core.content.ContextCompat;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
@ -59,7 +61,6 @@ import app.fedilab.android.interfaces.OnRetrieveWhoToFollowInterface;
public class WhoToFollowActivity extends BaseActivity implements OnRetrieveWhoToFollowInterface, OnPostActionInterface, OnListActionInterface {
private String item;
private List<String> followedId;
private List<String> accountListId;
@ -75,7 +76,7 @@ public class WhoToFollowActivity extends BaseActivity implements OnRetrieveWhoTo
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme){
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
break;
@ -92,30 +93,30 @@ public class WhoToFollowActivity extends BaseActivity implements OnRetrieveWhoTo
no_action = findViewById(R.id.no_action);
Toolbar toolbar = findViewById(R.id.toolbar);
progess_action = findViewById(R.id.progess_action);
if( theme == Helper.THEME_BLACK)
if (theme == Helper.THEME_BLACK)
toolbar.setBackgroundColor(ContextCompat.getColor(WhoToFollowActivity.this, R.color.black));
setSupportActionBar(toolbar);
if( getSupportActionBar() != null)
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mainLoader = findViewById(R.id.loader);
Bundle b = getIntent().getExtras();
if(b != null){
if (b != null) {
item = b.getString("item");
}
followedId = new ArrayList<>();
String lastDateListNameRefresh = sharedpreferences.getString(Helper.LAST_DATE_LIST_NAME_REFRESH+item, null);
String lastDateListNameRefresh = sharedpreferences.getString(Helper.LAST_DATE_LIST_NAME_REFRESH + item, null);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date( ));
cal.setTime(new Date());
cal.add(Calendar.MINUTE, -5);
Date dateAllowed = cal.getTime();
if( lastDateListNameRefresh == null || Helper.stringToDate(WhoToFollowActivity.this, lastDateListNameRefresh).before(dateAllowed)) {
if (lastDateListNameRefresh == null || Helper.stringToDate(WhoToFollowActivity.this, lastDateListNameRefresh).before(dateAllowed)) {
new WhoToFollowAsyncTask(WhoToFollowActivity.this, item, WhoToFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
mainLoader.setVisibility(View.VISIBLE);
}else {
} else {
String lastList = sharedpreferences.getString(Helper.LAST_LIST_NAME + item, null);
List<String> acctString = Helper.restoreArrayFromString(lastList);
if( acctString != null) {
if (acctString != null) {
trunkAccounts = new ArrayList<>();
for (String acct : acctString) {
TrunkAccount trunkAccount = new TrunkAccount();
@ -129,19 +130,19 @@ public class WhoToFollowActivity extends BaseActivity implements OnRetrieveWhoTo
}
private void displayResults(){
private void displayResults() {
mainLoader.setVisibility(View.GONE);
WhoToFollowAccountsAdapter whoToFollowAccountsAdapter;
if( trunkAccounts != null){
if( trunkAccounts.size() > 0) {
if (trunkAccounts != null) {
if (trunkAccounts.size() > 0) {
ListView lv_list = findViewById(R.id.lv_list);
whoToFollowAccountsAdapter = new WhoToFollowAccountsAdapter(trunkAccounts);
lv_list.setAdapter(whoToFollowAccountsAdapter);
}else {
} else {
no_action.setVisibility(View.VISIBLE);
return;
}
}else{
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_SHORT).show();
return;
}
@ -150,15 +151,15 @@ public class WhoToFollowActivity extends BaseActivity implements OnRetrieveWhoTo
follow_accounts_select.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(follow_accounts_select.getText().equals(getString(R.string.select_all))){
if (follow_accounts_select.getText().equals(getString(R.string.select_all))) {
follow_accounts_select.setText(R.string.unselect_all);
for(TrunkAccount trunkAccount: trunkAccounts){
for (TrunkAccount trunkAccount : trunkAccounts) {
trunkAccount.setChecked(true);
}
whoToFollowAccountsAdapter.notifyDataSetChanged();
}else {
} else {
follow_accounts_select.setText(R.string.select_all);
for(TrunkAccount trunkAccount: trunkAccounts){
for (TrunkAccount trunkAccount : trunkAccounts) {
trunkAccount.setChecked(false);
}
whoToFollowAccountsAdapter.notifyDataSetChanged();
@ -173,21 +174,21 @@ public class WhoToFollowActivity extends BaseActivity implements OnRetrieveWhoTo
follow_accounts_select.setEnabled(false);
progess_action.setVisibility(View.VISIBLE);
toFollowdId = new ArrayList<>();
for(TrunkAccount trunkAccount: trunkAccounts){
if( trunkAccount.isChecked()){
for (TrunkAccount trunkAccount : trunkAccounts) {
if (trunkAccount.isChecked()) {
toFollowdId.add(trunkAccount.getAcct());
}
}
if(toFollowdId.size() > 0){
if (toFollowdId.size() > 0) {
Account account = new Account();
String[] val = toFollowdId.get(0).split("@");
progess_action.setText(getString(R.string.follow_trunk, toFollowdId.get(0)));
if( val.length > 1){
if (val.length > 1) {
account.setAcct(val[0]);
account.setInstance(val[1]);
new PostActionAsyncTask(WhoToFollowActivity.this, null, account, API.StatusAction.FOLLOW, WhoToFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else {
Toasty.error(getApplicationContext(),getString(R.string.toast_impossible_to_follow), Toast.LENGTH_LONG).show();
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_impossible_to_follow), Toast.LENGTH_LONG).show();
follow_accounts.setEnabled(true);
follow_accounts_select.setEnabled(true);
progess_action.setVisibility(View.GONE);
@ -216,12 +217,12 @@ public class WhoToFollowActivity extends BaseActivity implements OnRetrieveWhoTo
@Override
public void onRetrieveWhoToFollowAccount(List<TrunkAccount> trunkAccounts) {
if( trunkAccounts != null){
if (trunkAccounts != null) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_DATE_LIST_NAME_REFRESH + item, Helper.dateToString(new Date()));
List<String> accounts = new ArrayList<>();
for(TrunkAccount trunkAccount: trunkAccounts)
for (TrunkAccount trunkAccount : trunkAccounts)
accounts.add(trunkAccount.getAcct());
editor.putString(Helper.LAST_LIST_NAME + item, Helper.arrayToStringStorage(accounts));
editor.apply();
@ -233,14 +234,14 @@ public class WhoToFollowActivity extends BaseActivity implements OnRetrieveWhoTo
@Override
public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) {
followedId.add(userId);
if( followedId != null && followedId.size() >= toFollowdId.size()) {
if (followedId != null && followedId.size() >= toFollowdId.size()) {
progess_action.setText(getString(R.string.create_list_trunk, item));
new ManageListsAsyncTask(WhoToFollowActivity.this, ManageListsAsyncTask.action.CREATE_LIST, null, null, null, item, WhoToFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else {
} else {
Account account = new Account();
String[] val = toFollowdId.get(followedId.size()).split("@");
progess_action.setText(getString(R.string.follow_trunk, toFollowdId.get(followedId.size())));
if( val.length > 1){
if (val.length > 1) {
account.setAcct(val[0]);
account.setInstance(val[1]);
new PostActionAsyncTask(WhoToFollowActivity.this, null, account, API.StatusAction.FOLLOW, WhoToFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -253,16 +254,16 @@ public class WhoToFollowActivity extends BaseActivity implements OnRetrieveWhoTo
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
List<app.fedilab.android.client.Entities.List> lists = apiResponse.getLists();
if( lists!= null && lists.size() > 0 && actionType == ManageListsAsyncTask.action.CREATE_LIST){
if (lists != null && lists.size() > 0 && actionType == ManageListsAsyncTask.action.CREATE_LIST) {
String[] accountsId = followedId.toArray(new String[0]);
progess_action.setText(R.string.add_account_list_trunk);
listId = lists.get(0).getId();
listTitle = lists.get(0).getTitle();
new ManageListsAsyncTask(WhoToFollowActivity.this, ManageListsAsyncTask.action.ADD_USERS, new String[]{followedId.get(0)}, null, lists.get(0).getId(), null, WhoToFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
accountListId = new ArrayList<>();
}else if(accountListId != null){
} else if (accountListId != null) {
if( accountListId.size() >= followedId.size() -1) {
if (accountListId.size() >= followedId.size() - 1) {
progess_action.setText(R.string.account_added_list_trunk);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@ -274,12 +275,12 @@ public class WhoToFollowActivity extends BaseActivity implements OnRetrieveWhoTo
b.putString("title", listTitle);
intent.putExtras(b);
startActivity(intent);
finish();
finish();
}
}, 1000);
}else {
} else {
accountListId.add(followedId.get(accountListId.size()));
progess_action.setText(R.string.adding_account_list_trunk);
String userIdToAdd = followedId.get(accountListId.size());

View File

@ -24,7 +24,7 @@ public class SlideMenuItem implements Resourceble {
@Override
public ContentSettingsFragment.type getType() {
return this.type;
return this.type;
}
public void setImageRes(int imageRes) {

View File

@ -36,7 +36,7 @@ public class ViewAnimator<T extends Resourceble> {
public static final int CIRCULAR_REVEAL_ANIMATION_DURATION = 500;
private AppCompatActivity appCompatActivity;
private List<T> list;
private List<View> viewList = new ArrayList<>();
@ -59,7 +59,6 @@ public class ViewAnimator<T extends Resourceble> {
}
public void showMenuContent() {
setViewsClickable(false);
viewList.clear();
@ -67,20 +66,20 @@ public class ViewAnimator<T extends Resourceble> {
for (int i = 0; i < size; i++) {
@SuppressLint("InflateParams") View viewMenu = appCompatActivity.getLayoutInflater().inflate(R.layout.menu_list_item, null);
if( i == SettingsActivity.position){
if (i == SettingsActivity.position) {
viewMenu.setBackgroundColor(ContextCompat.getColor(appCompatActivity, R.color.mastodonC2));
}else {
} else {
SharedPreferences sharedpreferences = appCompatActivity.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if (theme == Helper.THEME_DARK) {
viewMenu.setBackgroundResource(R.drawable.menu_item_selector);
} else if (theme == Helper.THEME_BLACK){
} else if (theme == Helper.THEME_BLACK) {
viewMenu.setBackgroundResource(R.drawable.menu_item_selector_black);
}else {
} else {
viewMenu.setBackgroundResource(R.drawable.menu_item_selector_light);
ImageView imageView = viewMenu.findViewById(R.id.menu_item_image);
if( imageView != null){
if (imageView != null) {
changeDrawableColor(appCompatActivity, imageView, R.color.black);
}
}
@ -104,7 +103,7 @@ public class ViewAnimator<T extends Resourceble> {
animatorListener.addViewToContainer(viewMenu);
final double position = i;
final double delay = 3 * ANIMATION_DURATION * (position / size);
if( screenShotable != null) {
if (screenShotable != null) {
new Handler().postDelayed(new Runnable() {
public void run() {
if (position < viewList.size()) {

View File

@ -18,6 +18,7 @@ import android.content.Context;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.client.Entities.AccountCreation;
@ -38,7 +39,7 @@ public class CreateMastodonAccountAsyncTask extends AsyncTask<Void, Void, Void>
private WeakReference<Context> contextReference;
private String instance;
public CreateMastodonAccountAsyncTask(Context context, AccountCreation accountCreation, String instance, OnPostStatusActionInterface onPostStatusActionInterface){
public CreateMastodonAccountAsyncTask(Context context, AccountCreation accountCreation, String instance, OnPostStatusActionInterface onPostStatusActionInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onPostStatusActionInterface;
this.accountCreation = accountCreation;

View File

@ -36,7 +36,7 @@ public class CustomSharingAsyncTask extends AsyncTask<Void, Void, Void> {
private OnCustomSharingInterface listener;
private WeakReference<Context> contextReference;
public CustomSharingAsyncTask(Context context, String encodedCustomSharingURL, OnCustomSharingInterface onCustomSharingInterface){
public CustomSharingAsyncTask(Context context, String encodedCustomSharingURL, OnCustomSharingInterface onCustomSharingInterface) {
this.contextReference = new WeakReference<>(context);
this.encodedCustomSharingURL = encodedCustomSharingURL;
this.listener = onCustomSharingInterface;

View File

@ -36,7 +36,7 @@ public class DeleteDomainsAsyncTask extends AsyncTask<Void, Void, Void> {
private int response;
private String domainName;
public DeleteDomainsAsyncTask(Context context, String domainName, OnRetrieveDomainsInterface onRetrieveDomainsInterface){
public DeleteDomainsAsyncTask(Context context, String domainName, OnRetrieveDomainsInterface onRetrieveDomainsInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveDomainsInterface;
this.domainName = domainName;

View File

@ -93,7 +93,7 @@ public class DownloadTrackingDomainsAsyncTask extends AsyncTask<Void, Void, Bool
mainHandler.post(() -> Toasty.success(context.get(), context.get().getString(R.string.tracking_db_updated), Toast.LENGTH_LONG).show());
else
mainHandler.post(() -> Toasty.error(context.get(), context.get().getString(R.string.toast_error), Toast.LENGTH_LONG).show());
if( update_tracking_domains != null && update_tracking_domains.get() != null) {
if (update_tracking_domains != null && update_tracking_domains.get() != null) {
update_tracking_domains.get().setEnabled(true);
}
}

View File

@ -36,9 +36,7 @@ public class ManageCachedStatusAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<Context> contextReference;
public ManageCachedStatusAsyncTask(Context context, String statusId, OnRefreshCachedStatusInterface onRefreshCachedStatusInterface){
public ManageCachedStatusAsyncTask(Context context, String statusId, OnRefreshCachedStatusInterface onRefreshCachedStatusInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRefreshCachedStatusInterface;
this.statusId = statusId;
@ -48,12 +46,12 @@ public class ManageCachedStatusAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
APIResponse apiResponse = new API(contextReference.get()).getStatusbyIdAndCache(statusId);
if( apiResponse.getStatuses().size() > 0){
if (apiResponse.getStatuses().size() > 0) {
refreshedStatus = apiResponse.getStatuses().get(0);
if( refreshedStatus != null){
if (refreshedStatus != null) {
refreshedStatus.setcached(true);
}
}else {
} else {
refreshedStatus = new app.fedilab.android.client.Entities.Status();
refreshedStatus.setId(statusId);

View File

@ -32,7 +32,7 @@ import app.fedilab.android.interfaces.OnFilterActionInterface;
public class ManageFiltersAsyncTask extends AsyncTask<Void, Void, Void> {
public enum action{
public enum action {
GET_FILTER,
GET_ALL_FILTER,
CREATE_FILTER,
@ -47,7 +47,7 @@ public class ManageFiltersAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<Context> contextReference;
private Filters filter;
public ManageFiltersAsyncTask(Context context, action apiAction, Filters filter, OnFilterActionInterface onFilterActionInterface){
public ManageFiltersAsyncTask(Context context, action apiAction, Filters filter, OnFilterActionInterface onFilterActionInterface) {
contextReference = new WeakReference<>(context);
this.listener = onFilterActionInterface;
this.filter = filter;
@ -59,13 +59,13 @@ public class ManageFiltersAsyncTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
if (apiAction == action.GET_ALL_FILTER) {
apiResponse = new API(contextReference.get()).getFilters();
}else if(apiAction == action.GET_FILTER){
} else if (apiAction == action.GET_FILTER) {
apiResponse = new API(contextReference.get()).getFilters(filter.getId());
}else if(apiAction == action.CREATE_FILTER){
} else if (apiAction == action.CREATE_FILTER) {
apiResponse = new API(contextReference.get()).addFilters(filter);
}else if( apiAction == action.UPDATE_FILTER){
} else if (apiAction == action.UPDATE_FILTER) {
apiResponse = new API(contextReference.get()).updateFilters(filter);
}else if(apiAction == action.DELETE_FILTER){
} else if (apiAction == action.DELETE_FILTER) {
statusCode = new API(contextReference.get()).deleteFilters(filter);
}
return null;

View File

@ -31,7 +31,7 @@ import app.fedilab.android.interfaces.OnListActionInterface;
public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
public enum action{
public enum action {
GET_LIST,
GET_LIST_TIMELINE,
GET_LIST_ACCOUNT,
@ -56,7 +56,7 @@ public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
private int limit;
private String search;
public ManageListsAsyncTask(Context context, action apiAction, String[] accountsId, String targetedId, String listId, String title, OnListActionInterface onListActionInterface){
public ManageListsAsyncTask(Context context, action apiAction, String[] accountsId, String targetedId, String listId, String title, OnListActionInterface onListActionInterface) {
contextReference = new WeakReference<>(context);
this.listener = onListActionInterface;
this.listId = listId;
@ -66,7 +66,7 @@ public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
this.targetedId = targetedId;
}
public ManageListsAsyncTask(Context context, String listId, String max_id, String since_id, OnListActionInterface onListActionInterface){
public ManageListsAsyncTask(Context context, String listId, String max_id, String since_id, OnListActionInterface onListActionInterface) {
contextReference = new WeakReference<>(context);
this.listener = onListActionInterface;
this.listId = listId;
@ -76,7 +76,7 @@ public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
this.apiAction = action.GET_LIST_TIMELINE;
}
public ManageListsAsyncTask(Context context, String search, OnListActionInterface onListActionInterface){
public ManageListsAsyncTask(Context context, String search, OnListActionInterface onListActionInterface) {
contextReference = new WeakReference<>(context);
this.listener = onListActionInterface;
this.search = search;
@ -87,21 +87,21 @@ public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
if (apiAction == action.GET_LIST) {
apiResponse = new API(contextReference.get()).getLists();
}else if(apiAction == action.GET_LIST_TIMELINE){
} else if (apiAction == action.GET_LIST_TIMELINE) {
apiResponse = new API(contextReference.get()).getListTimeline(this.listId, this.max_id, this.since_id, this.limit);
}else if(apiAction == action.GET_LIST_ACCOUNT){
apiResponse = new API(contextReference.get()).getAccountsInList(this.listId,0);
}else if( apiAction == action.CREATE_LIST){
} else if (apiAction == action.GET_LIST_ACCOUNT) {
apiResponse = new API(contextReference.get()).getAccountsInList(this.listId, 0);
} else if (apiAction == action.CREATE_LIST) {
apiResponse = new API(contextReference.get()).createList(this.title);
}else if(apiAction == action.DELETE_LIST){
} else if (apiAction == action.DELETE_LIST) {
statusCode = new API(contextReference.get()).deleteList(this.listId);
}else if(apiAction == action.UPDATE_LIST){
} else if (apiAction == action.UPDATE_LIST) {
apiResponse = new API(contextReference.get()).updateList(this.listId, this.title);
}else if(apiAction == action.ADD_USERS){
} else if (apiAction == action.ADD_USERS) {
apiResponse = new API(contextReference.get()).addAccountToList(this.listId, this.accountsId);
}else if(apiAction == action.DELETE_USERS){
} else if (apiAction == action.DELETE_USERS) {
statusCode = new API(contextReference.get()).deleteAccountFromList(this.listId, this.accountsId);
}else if( apiAction == action.SEARCH_USER){
} else if (apiAction == action.SEARCH_USER) {
apiResponse = new API(contextReference.get()).searchAccounts(this.search, 20, true);
}
return null;

View File

@ -39,7 +39,7 @@ import app.fedilab.android.sqlite.Sqlite;
public class ManagePlaylistsAsyncTask extends AsyncTask<Void, Void, Void> {
public enum action{
public enum action {
GET_PLAYLIST,
GET_LIST_VIDEOS,
CREATE_PLAYLIST,
@ -59,7 +59,7 @@ public class ManagePlaylistsAsyncTask extends AsyncTask<Void, Void, Void> {
private Playlist playlist;
private String videoId;
public ManagePlaylistsAsyncTask(Context context, action apiAction, Playlist playlist, String videoId, String max_id, OnPlaylistActionInterface onPlaylistActionInterface){
public ManagePlaylistsAsyncTask(Context context, action apiAction, Playlist playlist, String videoId, String max_id, OnPlaylistActionInterface onPlaylistActionInterface) {
contextReference = new WeakReference<>(context);
this.listener = onPlaylistActionInterface;
this.apiAction = apiAction;
@ -78,15 +78,15 @@ public class ManagePlaylistsAsyncTask extends AsyncTask<Void, Void, Void> {
Account account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, instance);
if (apiAction == action.GET_PLAYLIST) {
apiResponse = new PeertubeAPI(contextReference.get()).getPlayists(account.getUsername());
}else if(apiAction == action.GET_LIST_VIDEOS){
apiResponse = new PeertubeAPI(contextReference.get()).getPlaylistVideos(playlist.getId(),max_id, null);
}else if(apiAction == action.DELETE_PLAYLIST){
} else if (apiAction == action.GET_LIST_VIDEOS) {
apiResponse = new PeertubeAPI(contextReference.get()).getPlaylistVideos(playlist.getId(), max_id, null);
} else if (apiAction == action.DELETE_PLAYLIST) {
statusCode = new PeertubeAPI(contextReference.get()).deletePlaylist(playlist.getId());
}else if(apiAction == action.ADD_VIDEOS){
statusCode = new PeertubeAPI(contextReference.get()).addVideoPlaylist(playlist.getId(),videoId);
}else if(apiAction == action.DELETE_VIDEOS){
statusCode = new PeertubeAPI(contextReference.get()).deleteVideoPlaylist(playlist.getId(),videoId);
}else if(apiAction == action.GET_PLAYLIST_FOR_VIDEO){
} else if (apiAction == action.ADD_VIDEOS) {
statusCode = new PeertubeAPI(contextReference.get()).addVideoPlaylist(playlist.getId(), videoId);
} else if (apiAction == action.DELETE_VIDEOS) {
statusCode = new PeertubeAPI(contextReference.get()).deleteVideoPlaylist(playlist.getId(), videoId);
} else if (apiAction == action.GET_PLAYLIST_FOR_VIDEO) {
apiResponse = new PeertubeAPI(contextReference.get()).getPlaylistForVideo(videoId);
}
return null;

View File

@ -16,6 +16,7 @@ package app.fedilab.android.asynctasks;
import android.content.Context;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import app.fedilab.android.client.API;
@ -38,12 +39,12 @@ public class ManagePollAsyncTask extends AsyncTask<Void, Void, Void> {
private Poll poll;
private type_s type;
public enum type_s{
public enum type_s {
SUBMIT,
REFRESH
}
public ManagePollAsyncTask(Context context, type_s type, app.fedilab.android.client.Entities.Status status, int[] choices, OnPollInterface onPollInterface){
public ManagePollAsyncTask(Context context, type_s type, app.fedilab.android.client.Entities.Status status, int[] choices, OnPollInterface onPollInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onPollInterface;
this.status = status;
@ -54,16 +55,16 @@ public class ManagePollAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
Poll _poll;
if( status.getReblog() != null)
if (status.getReblog() != null)
_poll = status.getReblog().getPoll();
else
_poll = status.getPoll();
if( _poll.getId() == null)
if (_poll.getId() == null)
return null;
if (type == type_s.SUBMIT){
poll = new API(contextReference.get()).submiteVote(_poll.getId(),choices);
}else if( type == type_s.REFRESH){
if (type == type_s.SUBMIT) {
poll = new API(contextReference.get()).submiteVote(_poll.getId(), choices);
} else if (type == type_s.REFRESH) {
poll = new API(contextReference.get()).getPoll(status);
}
return null;

View File

@ -52,21 +52,21 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
private Error error;
private StoredStatus storedStatus;
public PostActionAsyncTask(Context context, API.StatusAction apiAction, StoredStatus storedStatus, OnPostActionInterface onPostActionInterface){
public PostActionAsyncTask(Context context, API.StatusAction apiAction, StoredStatus storedStatus, OnPostActionInterface onPostActionInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onPostActionInterface;
this.apiAction = apiAction;
this.storedStatus = storedStatus;
}
public PostActionAsyncTask(Context context, API.StatusAction apiAction, String targetedId, OnPostActionInterface onPostActionInterface){
public PostActionAsyncTask(Context context, API.StatusAction apiAction, String targetedId, OnPostActionInterface onPostActionInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onPostActionInterface;
this.apiAction = apiAction;
this.targetedId = targetedId;
}
public PostActionAsyncTask(Context context, Account account, API.StatusAction apiAction, String targetedId, OnPostActionInterface onPostActionInterface){
public PostActionAsyncTask(Context context, Account account, API.StatusAction apiAction, String targetedId, OnPostActionInterface onPostActionInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onPostActionInterface;
this.apiAction = apiAction;
@ -74,7 +74,7 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
this.account = account;
}
public PostActionAsyncTask(Context context, Account account, app.fedilab.android.client.Entities.Status remoteStatus, API.StatusAction apiAction, OnPostActionInterface onPostActionInterface){
public PostActionAsyncTask(Context context, Account account, app.fedilab.android.client.Entities.Status remoteStatus, API.StatusAction apiAction, OnPostActionInterface onPostActionInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onPostActionInterface;
this.apiAction = apiAction;
@ -82,7 +82,7 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
this.account = account;
}
public PostActionAsyncTask(Context context, Account account, Account remoteAccount, API.StatusAction apiAction, OnPostActionInterface onPostActionInterface){
public PostActionAsyncTask(Context context, Account account, Account remoteAccount, API.StatusAction apiAction, OnPostActionInterface onPostActionInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onPostActionInterface;
this.apiAction = apiAction;
@ -90,7 +90,7 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
this.account = account;
}
public PostActionAsyncTask(Context context, API.StatusAction apiAction, String targetedId, app.fedilab.android.client.Entities.Status status, String comment, OnPostActionInterface onPostActionInterface){
public PostActionAsyncTask(Context context, API.StatusAction apiAction, String targetedId, app.fedilab.android.client.Entities.Status status, String comment, OnPostActionInterface onPostActionInterface) {
contextReference = new WeakReference<>(context);
this.listener = onPostActionInterface;
this.apiAction = apiAction;
@ -98,7 +98,8 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
this.comment = comment;
this.status = status;
}
public PostActionAsyncTask(Context context, API.StatusAction apiAction, String targetedId, boolean muteNotifications, OnPostActionInterface onPostActionInterface){
public PostActionAsyncTask(Context context, API.StatusAction apiAction, String targetedId, boolean muteNotifications, OnPostActionInterface onPostActionInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onPostActionInterface;
this.apiAction = apiAction;
@ -107,7 +108,7 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
}
public PostActionAsyncTask(Context context, String targetedId, String comment, String targetedComment, OnPostActionInterface onPostActionInterface){
public PostActionAsyncTask(Context context, String targetedId, String comment, String targetedComment, OnPostActionInterface onPostActionInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onPostActionInterface;
this.apiAction = API.StatusAction.PEERTUBEREPLY;
@ -119,7 +120,7 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
//Remote action
API api;
if (account != null)
@ -162,26 +163,24 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
}
} else {
if (apiAction == API.StatusAction.REPORT) {
if( status != null ) {
if (status != null) {
statusCode = api.reportAction(status, comment);
}else{
} else {
statusCode = api.reportAction(targetedId, comment);
}
}
else if (apiAction == API.StatusAction.CREATESTATUS)
} else if (apiAction == API.StatusAction.CREATESTATUS)
statusCode = api.statusAction(status);
else if(apiAction == API.StatusAction.UPDATESERVERSCHEDULE) {
else if (apiAction == API.StatusAction.UPDATESERVERSCHEDULE) {
api.scheduledAction("PUT", storedStatus.getStatus(), null, storedStatus.getScheduledServerdId());
}
else if(apiAction == API.StatusAction.DELETESCHEDULED) {
} else if (apiAction == API.StatusAction.DELETESCHEDULED) {
api.scheduledAction("DELETE", null, null, storedStatus.getScheduledServerdId());
}else if (apiAction == API.StatusAction.MUTE_NOTIFICATIONS)
} else if (apiAction == API.StatusAction.MUTE_NOTIFICATIONS)
statusCode = api.muteNotifications(targetedId, muteNotifications);
else
statusCode = api.postAction(apiAction, targetedId);
}
error = api.getError();
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
//Remote action
PeertubeAPI peertubeAPI;
if (account != null)
@ -189,22 +188,22 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
else
peertubeAPI = new PeertubeAPI(contextReference.get());
if( apiAction == API.StatusAction.FOLLOW || apiAction == API.StatusAction.UNFOLLOW)
if (apiAction == API.StatusAction.FOLLOW || apiAction == API.StatusAction.UNFOLLOW)
statusCode = peertubeAPI.postAction(apiAction, targetedId);
else if( apiAction == API.StatusAction.RATEVIDEO )
else if (apiAction == API.StatusAction.RATEVIDEO)
statusCode = peertubeAPI.postRating(targetedId, comment);
else if( apiAction == API.StatusAction.PEERTUBECOMMENT)
else if (apiAction == API.StatusAction.PEERTUBECOMMENT)
statusCode = peertubeAPI.postComment(targetedId, comment);
else if( apiAction == API.StatusAction.PEERTUBEREPLY)
else if (apiAction == API.StatusAction.PEERTUBEREPLY)
statusCode = peertubeAPI.postReply(targetedId, comment, targetedComment);
else if( apiAction == API.StatusAction.PEERTUBEDELETECOMMENT) {
else if (apiAction == API.StatusAction.PEERTUBEDELETECOMMENT) {
statusCode = peertubeAPI.deleteComment(targetedId, comment);
targetedId = comment;
} else if( apiAction == API.StatusAction.PEERTUBEDELETEVIDEO) {
} else if (apiAction == API.StatusAction.PEERTUBEDELETEVIDEO) {
statusCode = peertubeAPI.deleteVideo(targetedId);
}
error = peertubeAPI.getError();
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
GNUAPI gnuapi;
if (account != null)
gnuapi = new GNUAPI(contextReference.get(), account.getInstance(), account.getToken());

View File

@ -18,6 +18,7 @@ import android.content.Context;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.client.Entities.AdminAction;
@ -25,7 +26,6 @@ import app.fedilab.android.helper.Helper;
import app.fedilab.android.interfaces.OnAdminActionInterface;
/**
* Created by Thomas on 18/06/2019.
* Makes actions for post admin calls
@ -41,8 +41,7 @@ public class PostAdminActionAsyncTask extends AsyncTask<Void, Void, Void> {
private AdminAction adminAction;
public PostAdminActionAsyncTask(Context context, API.adminAction action, String id, AdminAction adminAction, OnAdminActionInterface onAdminActionInterface){
public PostAdminActionAsyncTask(Context context, API.adminAction action, String id, AdminAction adminAction, OnAdminActionInterface onAdminActionInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onAdminActionInterface;
this.action = action;
@ -53,7 +52,7 @@ public class PostAdminActionAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
switch (action){
switch (action) {
case GET_ACCOUNTS:
case GET_ONE_ACCOUNT:
case GET_REPORTS:

View File

@ -36,7 +36,7 @@ public class PostNotificationsAsyncTask extends AsyncTask<Void, Void, Void> {
private String targetedId;
private WeakReference<Context> contextReference;
public PostNotificationsAsyncTask(Context context, String targetedId, OnPostNotificationsActionInterface onPostNotificationsActionInterface){
public PostNotificationsAsyncTask(Context context, String targetedId, OnPostNotificationsActionInterface onPostNotificationsActionInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onPostNotificationsActionInterface;
this.targetedId = targetedId;
@ -44,7 +44,7 @@ public class PostNotificationsAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
if( targetedId != null)
if (targetedId != null)
apiResponse = new API(this.contextReference.get()).postNoticationAction(targetedId);
else //Delete all notifications
apiResponse = new API(this.contextReference.get()).postNoticationAction(null);

View File

@ -33,27 +33,24 @@ import app.fedilab.android.interfaces.OnRetrievePeertubeInterface;
public class PostPeertubeAsyncTask extends AsyncTask<Void, Void, Void> {
private APIResponse apiResponse;
private OnRetrievePeertubeInterface listener;
private WeakReference<Context> contextReference;
private Peertube peertube;
public PostPeertubeAsyncTask(Context context, Peertube peertube, OnRetrievePeertubeInterface onRetrievePeertubeInterface){
public PostPeertubeAsyncTask(Context context, Peertube peertube, OnRetrievePeertubeInterface onRetrievePeertubeInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrievePeertubeInterface;
this.peertube = peertube;
}
@Override
protected Void doInBackground(Void... params) {
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
apiResponse = peertubeAPI.updateVideo(peertube);
if( apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0)
if (apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0)
apiResponse.getPeertubes().get(0).setUpdate(true);
return null;
}

View File

@ -48,7 +48,7 @@ public class PostStatusAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<Context> contextReference;
private UpdateAccountInfoAsyncTask.SOCIAL social;
public PostStatusAsyncTask(Context context, UpdateAccountInfoAsyncTask.SOCIAL social, Account account, app.fedilab.android.client.Entities.Status status, OnPostStatusActionInterface onPostStatusActionInterface){
public PostStatusAsyncTask(Context context, UpdateAccountInfoAsyncTask.SOCIAL social, Account account, app.fedilab.android.client.Entities.Status status, OnPostStatusActionInterface onPostStatusActionInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onPostStatusActionInterface;
this.status = status;
@ -59,28 +59,28 @@ public class PostStatusAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
if(social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
if (social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
boolean isconnected = Helper.isConnectedToInternet(contextReference.get(), Helper.getLiveInstance(contextReference.get()));
if( isconnected) {
if (isconnected) {
if (account == null) {
apiResponse = new API(this.contextReference.get()).postStatusAction(status);
} else
apiResponse = new API(this.contextReference.get(), account.getInstance(), account.getToken()).postStatusAction(status);
}else {
} else {
apiResponse = new APIResponse();
Error error = new Error();
error.setError(contextReference.get().getString(R.string.no_internet));
error.setStatusCode(-33);
apiResponse.setError(error);
}
}else {
} else {
boolean isconnected = Helper.isConnectedToInternet(contextReference.get(), Helper.getLiveInstance(contextReference.get()));
if( isconnected) {
if (isconnected) {
if (account == null) {
apiResponse = new GNUAPI(this.contextReference.get()).postStatusAction(status);
} else
apiResponse = new GNUAPI(this.contextReference.get(), account.getInstance(), account.getToken()).postStatusAction(status);
}else {
} else {
apiResponse = new APIResponse();
Error error = new Error();
error.setError(contextReference.get().getString(R.string.no_internet));
@ -90,7 +90,6 @@ public class PostStatusAsyncTask extends AsyncTask<Void, Void, Void> {
}
return null;
}
@ -102,21 +101,21 @@ public class PostStatusAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
public void run() {
String content = status.getContent();
if( content != null && content.length() > 0){
if (content != null && content.length() > 0) {
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Matcher matcher = Helper.hashtagPattern.matcher(content);
while (matcher.find()){
while (matcher.find()) {
int matchStart = matcher.start(1);
int matchEnd = matcher.end();
//Get cached tags
List<String> cachedTag = new TagsCacheDAO(contextReference.get(), db).getAll();
String tag = content.substring(matchStart, matchEnd);
tag = tag.replace("#","");
if( cachedTag == null){
tag = tag.replace("#", "");
if (cachedTag == null) {
new TagsCacheDAO(contextReference.get(), db).insert(tag);
}else {
} else {
//If cache doesn't contain the tag and the tag has upper case
if(!cachedTag.contains(tag) && !tag.toLowerCase().equals(tag)){
if (!cachedTag.contains(tag) && !tag.toLowerCase().equals(tag)) {
new TagsCacheDAO(contextReference.get(), db).insert(tag);
}
}

View File

@ -34,7 +34,7 @@ public class RemoveAccountAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<Activity> activityReference;
private Account account;
public RemoveAccountAsyncTask(Activity activity, Account account){
public RemoveAccountAsyncTask(Activity activity, Account account) {
activityReference = new WeakReference<>(activity);
this.account = account;
}

View File

@ -42,7 +42,7 @@ public class RetrieveAccountAsyncTask extends AsyncTask<Void, Void, Void> {
private Error error;
private WeakReference<Context> contextReference;
public RetrieveAccountAsyncTask(Context context, String targetedId, OnRetrieveAccountInterface onRetrieveAccountInterface){
public RetrieveAccountAsyncTask(Context context, String targetedId, OnRetrieveAccountInterface onRetrieveAccountInterface) {
this.contextReference = new WeakReference<>(context);
this.targetedId = targetedId;
this.listener = onRetrieveAccountInterface;
@ -50,15 +50,15 @@ public class RetrieveAccountAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
API api = new API(this.contextReference.get());
account = api.getAccount(targetedId);
error = api.getError();
}else if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
account = peertubeAPI.getAccount(targetedId);
error = peertubeAPI.getError();
}else if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU|| MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
account = gnuapi.getAccount(targetedId);
error = gnuapi.getError();

View File

@ -36,7 +36,7 @@ public class RetrieveAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
private API api;
private WeakReference<Context> contextReference;
public RetrieveAccountInfoAsyncTask(Context context, OnRetrieveAccountInterface onRetrieveAccountInterface){
public RetrieveAccountInfoAsyncTask(Context context, OnRetrieveAccountInterface onRetrieveAccountInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveAccountInterface;
}

View File

@ -41,7 +41,7 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<Context> contextReference;
private String instance, name;
public enum Type{
public enum Type {
BLOCKED,
MUTED,
FOLLOWING,
@ -53,7 +53,7 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
GROUPS
}
public RetrieveAccountsAsyncTask(Context context, String instance, String name, OnRetrieveAccountsInterface onRetrieveAccountsInterface){
public RetrieveAccountsAsyncTask(Context context, String instance, String name, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
this.contextReference = new WeakReference<>(context);
this.instance = instance;
this.name = name;
@ -61,7 +61,7 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
this.action = Type.CHANNELS;
}
public RetrieveAccountsAsyncTask(Context context, Type action, String targetedId, String max_id, OnRetrieveAccountsInterface onRetrieveAccountsInterface){
public RetrieveAccountsAsyncTask(Context context, Type action, String targetedId, String max_id, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
this.contextReference = new WeakReference<>(context);
this.action = action;
this.max_id = max_id;
@ -69,7 +69,7 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
this.targetedId = targetedId;
}
public RetrieveAccountsAsyncTask(Context context, Type action, String max_id, OnRetrieveAccountsInterface onRetrieveAccountsInterface){
public RetrieveAccountsAsyncTask(Context context, Type action, String max_id, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
this.contextReference = new WeakReference<>(context);
this.action = action;
this.max_id = max_id;
@ -80,16 +80,16 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
API api = null;
GNUAPI gnuapi = null;
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
api = new API(this.contextReference.get());
else
gnuapi = new GNUAPI(this.contextReference.get());
switch (action){
switch (action) {
case REBLOGGED:
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
assert api != null;
apiResponse = api.getRebloggedBy(targetedId, max_id);
}else {
} else {
assert gnuapi != null;
apiResponse = gnuapi.getRebloggedBy(targetedId, max_id);
}
@ -99,47 +99,46 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
apiResponse = api.search2(targetedId, API.searchType.ACCOUNTS, max_id);
break;
case FAVOURITED:
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
assert api != null;
apiResponse = api.getFavouritedBy(targetedId, max_id);
}else {
} else {
assert gnuapi != null;
apiResponse = gnuapi.getFavouritedBy(targetedId, max_id);
}
break;
case BLOCKED:
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
assert api != null;
apiResponse = api.getBlocks(max_id);
}else {
} else {
assert gnuapi != null;
apiResponse = gnuapi.getBlocks(max_id);
}
break;
case MUTED:
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
assert api != null;
apiResponse = api.getMuted(max_id);
}else {
} else {
assert gnuapi != null;
apiResponse = gnuapi.getMuted(max_id);
}
break;
case FOLLOWING:
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
assert api != null;
apiResponse = api.getFollowing(targetedId, max_id);
}
else {
} else {
assert gnuapi != null;
apiResponse = gnuapi.getFollowing(targetedId, max_id);
}
break;
case FOLLOWERS:
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
assert api != null;
apiResponse = api.getFollowers(targetedId, max_id);
}else {
} else {
assert gnuapi != null;
apiResponse = gnuapi.getFollowers(targetedId, max_id);
}

View File

@ -43,7 +43,7 @@ public class RetrieveAccountsForReplyAsyncTask extends AsyncTask<Void, Void, Voi
private ArrayList<Account> accounts;
private WeakReference<Context> contextReference;
public RetrieveAccountsForReplyAsyncTask(Context context, app.fedilab.android.client.Entities.Status status, OnRetrieveAccountsReplyInterface onRetrieveAccountsReplyInterface){
public RetrieveAccountsForReplyAsyncTask(Context context, app.fedilab.android.client.Entities.Status status, OnRetrieveAccountsReplyInterface onRetrieveAccountsReplyInterface) {
this.contextReference = new WeakReference<>(context);
this.status = status;
this.listener = onRetrieveAccountsReplyInterface;
@ -59,20 +59,20 @@ public class RetrieveAccountsForReplyAsyncTask extends AsyncTask<Void, Void, Voi
addedAccounts.add(status.getAccount().getAcct());
//Retrieves the first toot
if( statusContext.getAncestors().size() > 0 ) {
if (statusContext.getAncestors().size() > 0) {
statusContext = api.getStatusContext(statusContext.getAncestors().get(0).getId());
}
if( statusContext != null && statusContext.getDescendants().size() > 0){
for(app.fedilab.android.client.Entities.Status status : statusContext.getDescendants()){
if( canBeAdded(status.getAccount().getAcct())){
if (statusContext != null && statusContext.getDescendants().size() > 0) {
for (app.fedilab.android.client.Entities.Status status : statusContext.getDescendants()) {
if (canBeAdded(status.getAccount().getAcct())) {
accounts.add(status.getAccount());
addedAccounts.add(status.getAccount().getAcct());
}
}
}
if( statusContext != null && statusContext.getAncestors().size() > 0){
for(app.fedilab.android.client.Entities.Status status : statusContext.getAncestors()){
if( canBeAdded(status.getAccount().getAcct())){
if (statusContext != null && statusContext.getAncestors().size() > 0) {
for (app.fedilab.android.client.Entities.Status status : statusContext.getAncestors()) {
if (canBeAdded(status.getAccount().getAcct())) {
accounts.add(status.getAccount());
addedAccounts.add(status.getAccount().getAcct());
}
@ -81,7 +81,7 @@ public class RetrieveAccountsForReplyAsyncTask extends AsyncTask<Void, Void, Voi
return null;
}
private boolean canBeAdded(String acct){
private boolean canBeAdded(String acct) {
final SharedPreferences sharedpreferences = this.contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);

View File

@ -41,7 +41,7 @@ public class RetrieveChartsAsyncTask extends AsyncTask<Void, Void, Void> {
private Date dateIni;
private Date dateEnd;
public RetrieveChartsAsyncTask(Context context, Date dateIni, Date dateEnd, OnRetrieveChartsInterface onRetrieveChartsInterface){
public RetrieveChartsAsyncTask(Context context, Date dateIni, Date dateEnd, OnRetrieveChartsInterface onRetrieveChartsInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveChartsInterface;
this.dateIni = dateIni;

View File

@ -42,7 +42,7 @@ public class RetrieveContextAsyncTask extends AsyncTask<Void, Void, Void> {
private boolean directtimeline;
public RetrieveContextAsyncTask(Context context, boolean expanded, boolean directtimeline, String statusId, OnRetrieveContextInterface onRetrieveContextInterface){
public RetrieveContextAsyncTask(Context context, boolean expanded, boolean directtimeline, String statusId, OnRetrieveContextInterface onRetrieveContextInterface) {
this.contextReference = new WeakReference<>(context);
this.statusId = statusId;
this.listener = onRetrieveContextInterface;
@ -52,7 +52,7 @@ public class RetrieveContextAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
API api = new API(this.contextReference.get());
statusContext = api.getStatusContext(statusId);
//Retrieves the first toot
@ -60,7 +60,7 @@ public class RetrieveContextAsyncTask extends AsyncTask<Void, Void, Void> {
statusContext = api.getStatusContext(statusContext.getAncestors().get(0).getId());
}
error = api.getError();
}else{
} else {
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
statusContext = gnuapi.getStatusContext(statusId, directtimeline);
//Retrieves the first toot

View File

@ -37,7 +37,7 @@ public class RetrieveDomainsAsyncTask extends AsyncTask<Void, Void, Void> {
private APIResponse apiResponse;
private String max_id;
public RetrieveDomainsAsyncTask(Context context, String max_id, OnRetrieveDomainsInterface onRetrieveDomainsInterface){
public RetrieveDomainsAsyncTask(Context context, String max_id, OnRetrieveDomainsInterface onRetrieveDomainsInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveDomainsInterface;
this.max_id = max_id;

View File

@ -39,7 +39,7 @@ public class RetrieveEmojiAsyncTask extends AsyncTask<Void, Void, Void> {
private OnRetrieveEmojiInterface listener;
private WeakReference<Context> contextReference;
public RetrieveEmojiAsyncTask(Context context, String shortcode, OnRetrieveEmojiInterface onRetrieveEmojiInterface){
public RetrieveEmojiAsyncTask(Context context, String shortcode, OnRetrieveEmojiInterface onRetrieveEmojiInterface) {
this.contextReference = new WeakReference<>(context);
this.shortcode = shortcode;
this.listener = onRetrieveEmojiInterface;

View File

@ -39,7 +39,7 @@ public class RetrieveFeedsAfterBookmarkAsyncTask extends AsyncTask<Void, Void, V
private String max_id;
private boolean fetchMore;
public RetrieveFeedsAfterBookmarkAsyncTask(Context context, String max_id, boolean fetchMore, OnRetrieveFeedsAfterBookmarkInterface onRetrieveFeedsAfterBookmarkInterface){
public RetrieveFeedsAfterBookmarkAsyncTask(Context context, String max_id, boolean fetchMore, OnRetrieveFeedsAfterBookmarkInterface onRetrieveFeedsAfterBookmarkInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveFeedsAfterBookmarkInterface;
this.max_id = max_id;

View File

@ -64,13 +64,13 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
private boolean showReply = false;
private WeakReference<Context> contextReference;
private FilterToots filterToots;
private String instanceName,remoteInstance, name;
private String instanceName, remoteInstance, name;
private boolean cached = false;
private int timelineId;
private String currentfilter;
private String social;
public enum Type{
public enum Type {
HOME,
LOCAL,
DIRECT,
@ -125,7 +125,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
}
public RetrieveFeedsAsyncTask(Context context, FilterToots filterToots, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
public RetrieveFeedsAsyncTask(Context context, FilterToots filterToots, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.action = Type.CACHE_STATUS;
this.max_id = max_id;
@ -134,14 +134,14 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
}
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.action = action;
this.max_id = max_id;
this.listener = onRetrieveFeedsInterface;
}
public RetrieveFeedsAsyncTask(Context context, Type action, String instanceName, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
public RetrieveFeedsAsyncTask(Context context, Type action, String instanceName, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.action = action;
this.max_id = max_id;
@ -149,7 +149,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
this.instanceName = instanceName;
}
public RetrieveFeedsAsyncTask(Context context, Type action, int timelineId, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
public RetrieveFeedsAsyncTask(Context context, Type action, int timelineId, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.action = action;
this.max_id = max_id;
@ -157,7 +157,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
this.timelineId = timelineId;
}
public RetrieveFeedsAsyncTask(Context context, Type action, String targetedID, String max_id, boolean showMediaOnly, boolean showPinned, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
public RetrieveFeedsAsyncTask(Context context, Type action, String targetedID, String max_id, boolean showMediaOnly, boolean showPinned, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.action = action;
this.max_id = max_id;
@ -166,7 +166,8 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
this.showMediaOnly = showMediaOnly;
this.showPinned = showPinned;
}
public RetrieveFeedsAsyncTask(Context context, Type action, String targetedID, String max_id, boolean showMediaOnly, boolean showPinned, boolean showReply, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
public RetrieveFeedsAsyncTask(Context context, Type action, String targetedID, String max_id, boolean showMediaOnly, boolean showPinned, boolean showReply, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.action = action;
this.max_id = max_id;
@ -176,7 +177,8 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
this.showPinned = showPinned;
this.showReply = showReply;
}
public RetrieveFeedsAsyncTask(Context context, Type action, String tag, String targetedID, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
public RetrieveFeedsAsyncTask(Context context, Type action, String tag, String targetedID, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.action = action;
this.max_id = max_id;
@ -185,7 +187,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
this.tag = tag;
}
public RetrieveFeedsAsyncTask(Context context, String remoteInstance, String name, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
public RetrieveFeedsAsyncTask(Context context, String remoteInstance, String name, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.remoteInstance = remoteInstance;
this.max_id = max_id;
@ -194,7 +196,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
this.action = Type.REMOTE_INSTANCE;
}
public RetrieveFeedsAsyncTask(Context context, RetrieveFeedsParam retrieveFeedsParam, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
public RetrieveFeedsAsyncTask(Context context, RetrieveFeedsParam retrieveFeedsParam, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveFeedsInterface;
this.action = retrieveFeedsParam.getAction();
@ -216,9 +218,9 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
API api = new API(this.contextReference.get());
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
if( action == null )
if (action == null)
return null;
switch (action){
switch (action) {
case HOME:
apiResponse = api.getHomeTimelineCache(max_id);
break;
@ -241,70 +243,70 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
apiResponse = api.getConversationTimeline(max_id);
break;
case REMOTE_INSTANCE_FILTERED:
if( this.social != null && this.social.equals("MASTODON")) {
apiResponse = api.getPublicTimelineTag(this.currentfilter, true, max_id,this.remoteInstance);
if( apiResponse != null){
if (this.social != null && this.social.equals("MASTODON")) {
apiResponse = api.getPublicTimelineTag(this.currentfilter, true, max_id, this.remoteInstance);
if (apiResponse != null) {
List<app.fedilab.android.client.Entities.Status> statusesTemp = apiResponse.getStatuses();
if( statusesTemp != null){
for(app.fedilab.android.client.Entities.Status status: statusesTemp){
if (statusesTemp != null) {
for (app.fedilab.android.client.Entities.Status status : statusesTemp) {
status.setType(action);
}
}
}
} else if(this.social != null && this.social.equals("GNU") ) {
} else if (this.social != null && this.social.equals("GNU")) {
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
apiResponse = gnuapi.searchRemote(this.remoteInstance,currentfilter,max_id);
}else {
apiResponse = gnuapi.searchRemote(this.remoteInstance, currentfilter, max_id);
} else {
apiResponse = api.searchPeertube(this.remoteInstance, currentfilter);
}
break;
case REMOTE_INSTANCE:
if( this.name != null && this.remoteInstance != null){ //For Peertube channels
if (this.name != null && this.remoteInstance != null) { //For Peertube channels
apiResponse = api.getPeertubeChannelVideos(this.remoteInstance, this.name);
}else{ //For other remote instance
} else { //For other remote instance
List<RemoteInstance> remoteInstanceObj = new InstancesDAO(this.contextReference.get(), db).getInstanceByName(this.instanceName);
if( remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("MASTODON")) {
if (remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("MASTODON")) {
apiResponse = api.getPublicTimeline(this.instanceName, true, max_id);
List<app.fedilab.android.client.Entities.Status> statusesTemp = apiResponse.getStatuses();
if( statusesTemp != null){
for(app.fedilab.android.client.Entities.Status status: statusesTemp){
if (statusesTemp != null) {
for (app.fedilab.android.client.Entities.Status status : statusesTemp) {
status.setType(action);
}
}
}else if(remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("MISSKEY")){
} else if (remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("MISSKEY")) {
apiResponse = api.getMisskey(this.instanceName, max_id);
List<app.fedilab.android.client.Entities.Status> statusesTemp = apiResponse.getStatuses();
if( statusesTemp != null){
for(app.fedilab.android.client.Entities.Status status: statusesTemp){
if (statusesTemp != null) {
for (app.fedilab.android.client.Entities.Status status : statusesTemp) {
status.setType(action);
}
}
} else if(remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("PIXELFED") ) {
} else if (remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("PIXELFED")) {
apiResponse = api.getPixelfedTimeline(instanceName, max_id);
} else if(remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("GNU") ) {
} else if (remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("GNU")) {
apiResponse = api.getGNUTimeline(instanceName, max_id);
}else {
} else {
apiResponse = api.getPeertube(this.instanceName, max_id);
}
}
break;
case FAVOURITES:
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
apiResponse = api.getFavourites(max_id);
}else{
} else {
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
apiResponse = gnuapi.getFavourites(max_id);
}
break;
case USER:
if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
if (showMediaOnly)
apiResponse = api.getStatusWithMedia(targetedID, max_id);
else if (showPinned)
apiResponse = api.getPinnedStatuses(targetedID, max_id);
else
apiResponse = api.getAccountTLStatuses(targetedID, max_id, !showReply);
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
if (showMediaOnly)
apiResponse = gnuapi.getStatusWithMedia(targetedID, max_id);
@ -312,7 +314,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
apiResponse = gnuapi.getPinnedStatuses(targetedID, max_id);
else
apiResponse = gnuapi.getAccountTLStatuses(targetedID, max_id, !showReply);
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
apiResponse = peertubeAPI.getVideos(targetedID, max_id);
}
@ -334,20 +336,20 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
break;
case SEARCH:
if( !tag.contains("_cache_")) {
if (!tag.contains("_cache_")) {
apiResponse = api.search2(tag, API.searchType.STATUSES, max_id);
}else{
tag = tag.replace("_cache_","");
} else {
tag = tag.replace("_cache_", "");
apiResponse = new APIResponse();
Results results = new Results();
List<app.fedilab.android.client.Entities.Status> statuses = new TimelineCacheDAO(contextReference.get(), db).search(tag, max_id);
if( statuses != null && statuses.size() > 0 ) {
if (statuses != null && statuses.size() > 0) {
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
}
List<app.fedilab.android.client.Entities.Status> statusesNew = null;
if( statuses != null){
if (statuses != null) {
statusesNew = new ArrayList<>();
for(app.fedilab.android.client.Entities.Status status: statuses){
for (app.fedilab.android.client.Entities.Status status : statuses) {
if (tag != null && !tag.contains("\"")) {
String[] searches = tag.split(" ");
for (String search : searches) {
@ -355,7 +357,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
statusesNew.add(status);
}
}
}else{
} else {
statusesNew.addAll(statuses);
}
}
@ -366,20 +368,20 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
}
break;
case TAG:
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
ManageTimelines manageTimelines = new TimelinesDAO(contextReference.get(), db).getById(timelineId);
if( manageTimelines != null && manageTimelines.getTagTimeline() != null){
if (manageTimelines != null && manageTimelines.getTagTimeline() != null) {
boolean isArt = manageTimelines.getTagTimeline().isART();
if (isArt)
apiResponse = api.getCustomArtTimeline(false, manageTimelines.getTagTimeline().getName(), max_id, manageTimelines.getTagTimeline().getAny(), manageTimelines.getTagTimeline().getAll(), manageTimelines.getTagTimeline().getNone());
apiResponse = api.getCustomArtTimeline(false, manageTimelines.getTagTimeline().getName(), max_id, manageTimelines.getTagTimeline().getAny(), manageTimelines.getTagTimeline().getAll(), manageTimelines.getTagTimeline().getNone());
else
apiResponse = api.getPublicTimelineTag(manageTimelines.getTagTimeline().getName(), false, max_id, manageTimelines.getTagTimeline().getAny(), manageTimelines.getTagTimeline().getAll(), manageTimelines.getTagTimeline().getNone());
}else{
} else {
apiResponse = api.getPublicTimelineTag(tag, false, max_id, null, null, null);
}
}else{
} else {
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
apiResponse = gnuapi.search(tag,max_id);
apiResponse = gnuapi.search(tag, max_id);
}
break;
@ -402,11 +404,11 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
apiResponse = new APIResponse();
db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
statuses = new StatusCacheDAO(contextReference.get(), db).getStatusFromID(StatusCacheDAO.ARCHIVE_CACHE, filterToots, max_id);
if( statuses != null && statuses.size() > 0) {
if (statuses != null && statuses.size() > 0) {
apiResponse.setStatuses(statuses);
apiResponse.setSince_id(statuses.get(0).getId());
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
}else{
} else {
apiResponse.setStatuses(null);
apiResponse.setMax_id(null);
apiResponse.setSince_id(null);
@ -443,10 +445,10 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
break;
case PF_LOCAL:
api = new API(this.contextReference.get());
apiResponse = api.getPublicTimeline(true,max_id);
apiResponse = api.getPublicTimeline(true, max_id);
case PF_DISCOVER:
api = new API(this.contextReference.get());
apiResponse = api.getDiscoverTimeline(true,max_id);
apiResponse = api.getDiscoverTimeline(true, max_id);
break;
case HASHTAG:
break;
@ -457,11 +459,11 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
break;
case GNU_LOCAL:
gnuAPI = new GNUAPI(this.contextReference.get());
apiResponse = gnuAPI.getPublicTimeline(true,max_id);
apiResponse = gnuAPI.getPublicTimeline(true, max_id);
break;
case GNU_WHOLE:
gnuAPI = new GNUAPI(this.contextReference.get());
apiResponse = gnuAPI.getPublicTimeline(false,max_id);
apiResponse = gnuAPI.getPublicTimeline(false, max_id);
break;
case GNU_DM:
gnuAPI = new GNUAPI(this.contextReference.get());
@ -472,7 +474,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
apiResponse = gnuAPI.getGroupTimeline(tag.trim(), max_id);
break;
}
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
List<String> bookmarks = new StatusCacheDAO(contextReference.get(), db).getAllStatusId(StatusCacheDAO.BOOKMARK_CACHE);
if (apiResponse != null && apiResponse.getStatuses() != null && bookmarks != null && apiResponse.getStatuses().size() > 0) {
List<app.fedilab.android.client.Entities.Status> statuses = apiResponse.getStatuses();

View File

@ -37,7 +37,7 @@ public class RetrieveFollowRequestSentAsyncTask extends AsyncTask<Void, Void, Vo
private OnRetrieveAccountsInterface listener;
private WeakReference<Context> contextReference;
public RetrieveFollowRequestSentAsyncTask(Context context, String max_id, OnRetrieveAccountsInterface onRetrieveAccountsInterface){
public RetrieveFollowRequestSentAsyncTask(Context context, String max_id, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
this.contextReference = new WeakReference<>(context);
this.max_id = max_id;
this.listener = onRetrieveAccountsInterface;

View File

@ -16,6 +16,7 @@ package app.fedilab.android.asynctasks;
import android.content.Context;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import app.fedilab.android.client.API;
@ -36,8 +37,7 @@ public class RetrieveHowToAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<Context> contextReference;
public RetrieveHowToAsyncTask(Context context, OnRetrieveHowToInterface onRetrieveHowToInterface){
public RetrieveHowToAsyncTask(Context context, OnRetrieveHowToInterface onRetrieveHowToInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveHowToInterface;
}

View File

@ -35,7 +35,7 @@ public class RetrieveInstanceAsyncTask extends AsyncTask<Void, Void, Void> {
private APIResponse apiResponse;
private WeakReference<Context> contextReference;
public RetrieveInstanceAsyncTask(Context context, OnRetrieveInstanceInterface onRetrieveInstanceInterface){
public RetrieveInstanceAsyncTask(Context context, OnRetrieveInstanceInterface onRetrieveInstanceInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveInstanceInterface;
}

View File

@ -36,7 +36,7 @@ public class RetrieveInstanceRegAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<Context> contextReference;
private String category;
public RetrieveInstanceRegAsyncTask(Context context, String category, OnRetrieveInstanceInterface onRetrieveInstanceInterface){
public RetrieveInstanceRegAsyncTask(Context context, String category, OnRetrieveInstanceInterface onRetrieveInstanceInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveInstanceInterface;
this.category = category;

View File

@ -40,7 +40,7 @@ public class RetrieveManyRelationshipsAsyncTask extends AsyncTask<Void, Void, Vo
private APIResponse apiResponse;
private WeakReference<Context> contextReference;
public RetrieveManyRelationshipsAsyncTask(Context context, List<Account> accounts, OnRetrieveManyRelationshipsInterface onRetrieveManyRelationshipsInterface){
public RetrieveManyRelationshipsAsyncTask(Context context, List<Account> accounts, OnRetrieveManyRelationshipsInterface onRetrieveManyRelationshipsInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveManyRelationshipsInterface;
this.accounts = accounts;
@ -48,7 +48,7 @@ public class RetrieveManyRelationshipsAsyncTask extends AsyncTask<Void, Void, Vo
@Override
protected Void doInBackground(Void... params) {
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
apiResponse = new API(this.contextReference.get()).getRelationship(accounts);
else
apiResponse = new GNUAPI(this.contextReference.get()).getRelationship(accounts);

View File

@ -45,7 +45,8 @@ public class RetrieveMetaDataAsyncTask extends AsyncTask<Void, Void, Void> {
private String image, title, description, sharedSubject, sharedText;
private WeakReference<Context> contextWeakReference;
private boolean shouldFetchMetaData = true;
public RetrieveMetaDataAsyncTask(Context context,boolean shouldFetchMetaData, String sharedSubject, String sharedText,String url, OnRetrieveMetaDataInterface onRetrieveRemoteAccountInterface){
public RetrieveMetaDataAsyncTask(Context context, boolean shouldFetchMetaData, String sharedSubject, String sharedText, String url, OnRetrieveMetaDataInterface onRetrieveRemoteAccountInterface) {
this.url = url;
this.listener = onRetrieveRemoteAccountInterface;
this.sharedText = sharedText;
@ -56,12 +57,13 @@ public class RetrieveMetaDataAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
if(shouldFetchMetaData)
if (shouldFetchMetaData)
return execRetrieveMetaDataInBackground();
else
return null;
}
private Void execRetrieveMetaDataInBackground(){
private Void execRetrieveMetaDataInBackground() {
String potentialUrl = "";
if (url == null) {
@ -77,10 +79,10 @@ public class RetrieveMetaDataAsyncTask extends AsyncTask<Void, Void, Void> {
matcher = Patterns.WEB_URL.matcher(url);
else
matcher = Helper.urlPattern.matcher(url);
while (matcher.find()){
while (matcher.find()) {
int matchStart = matcher.start(1);
int matchEnd = matcher.end();
if(matchStart < matchEnd && url.length() >= matchEnd)
if (matchStart < matchEnd && url.length() >= matchEnd)
potentialUrl = url.substring(matchStart, matchEnd);
}
// If we actually have a URL then make use of it.
@ -103,15 +105,15 @@ public class RetrieveMetaDataAsyncTask extends AsyncTask<Void, Void, Void> {
image = matcherImage.group(1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if( titleEncoded != null)
if (titleEncoded != null)
title = Html.fromHtml(titleEncoded, Html.FROM_HTML_MODE_LEGACY).toString();
if( descriptionEncoded != null)
if (descriptionEncoded != null)
description = Html.fromHtml(descriptionEncoded, Html.FROM_HTML_MODE_LEGACY).toString();
}else {
} else {
//noinspection deprecation
if( titleEncoded != null)
if (titleEncoded != null)
title = Html.fromHtml(titleEncoded).toString();
if( descriptionEncoded != null)
if (descriptionEncoded != null)
description = Html.fromHtml(descriptionEncoded).toString();
}
} catch (NoSuchAlgorithmException e) {
@ -127,6 +129,7 @@ public class RetrieveMetaDataAsyncTask extends AsyncTask<Void, Void, Void> {
}
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveMetaData(error, sharedSubject, sharedText, image, title, description);

View File

@ -51,14 +51,14 @@ public class RetrieveMissingFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
private String remoteInstance;
private int timelineId;
public RetrieveMissingFeedsAsyncTask(Context context, String since_id, RetrieveFeedsAsyncTask.Type type, OnRetrieveMissingFeedsInterface onRetrieveMissingFeedsInterface){
public RetrieveMissingFeedsAsyncTask(Context context, String since_id, RetrieveFeedsAsyncTask.Type type, OnRetrieveMissingFeedsInterface onRetrieveMissingFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.since_id = since_id;
this.listener = onRetrieveMissingFeedsInterface;
this.type = type;
}
public RetrieveMissingFeedsAsyncTask(Context context, String remoteInstance, String since_id, RetrieveFeedsAsyncTask.Type type, OnRetrieveMissingFeedsInterface onRetrieveMissingFeedsInterface){
public RetrieveMissingFeedsAsyncTask(Context context, String remoteInstance, String since_id, RetrieveFeedsAsyncTask.Type type, OnRetrieveMissingFeedsInterface onRetrieveMissingFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.since_id = since_id;
this.listener = onRetrieveMissingFeedsInterface;
@ -66,7 +66,7 @@ public class RetrieveMissingFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
this.remoteInstance = remoteInstance;
}
public RetrieveMissingFeedsAsyncTask(Context context, int timelineId, String since_id, RetrieveFeedsAsyncTask.Type type, OnRetrieveMissingFeedsInterface onRetrieveMissingFeedsInterface){
public RetrieveMissingFeedsAsyncTask(Context context, int timelineId, String since_id, RetrieveFeedsAsyncTask.Type type, OnRetrieveMissingFeedsInterface onRetrieveMissingFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.since_id = since_id;
this.listener = onRetrieveMissingFeedsInterface;
@ -77,9 +77,9 @@ public class RetrieveMissingFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
if( this.contextReference.get() == null)
if (this.contextReference.get() == null)
return null;
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
API api = new API(this.contextReference.get());
List<app.fedilab.android.client.Entities.Status> tempStatus = null;
APIResponse apiResponse = null;
@ -98,7 +98,7 @@ public class RetrieveMissingFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
else if (type == RetrieveFeedsAsyncTask.Type.TAG) {
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
ManageTimelines manageTimelines = new TimelinesDAO(contextReference.get(), db).getById(timelineId);
if( manageTimelines != null && manageTimelines.getTagTimeline() != null){
if (manageTimelines != null && manageTimelines.getTagTimeline() != null) {
TagTimeline tagTimeline = manageTimelines.getTagTimeline();
boolean isArt = tagTimeline.isART();
if (isArt)
@ -117,7 +117,7 @@ public class RetrieveMissingFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
if (conversations != null && conversations.size() > 0) {
for (Conversation conversation : conversations) {
app.fedilab.android.client.Entities.Status status = conversation.getLast_status();
if( status != null) {
if (status != null) {
List<String> ppConversation = new ArrayList<>();
for (Account account : conversation.getAccounts())
ppConversation.add(account.getAvatar());
@ -135,13 +135,13 @@ public class RetrieveMissingFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
if (type == RetrieveFeedsAsyncTask.Type.HOME && statuses.size() > 0) {
MainActivity.lastHomeId = statuses.get(0).getId();
}
}else{
} else {
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
List<app.fedilab.android.client.Entities.Status> tempStatus = null;
APIResponse apiResponse = null;
if (type == RetrieveFeedsAsyncTask.Type.GNU_HOME) {
apiResponse = gnuapi.getHomeTimelineSinceId(since_id);
}else if (type == RetrieveFeedsAsyncTask.Type.GNU_LOCAL)
} else if (type == RetrieveFeedsAsyncTask.Type.GNU_LOCAL)
apiResponse = gnuapi.getPublicTimelineSinceId(true, since_id);
else if (type == RetrieveFeedsAsyncTask.Type.GNU_WHOLE)
apiResponse = gnuapi.getPublicTimelineSinceId(false, since_id);

View File

@ -44,7 +44,7 @@ public class RetrieveMissingNotificationsAsyncTask extends AsyncTask<Void, Void,
private DisplayNotificationsFragment.Type type;
private Error error;
public RetrieveMissingNotificationsAsyncTask(Context context, DisplayNotificationsFragment.Type type, String since_id, OnRetrieveMissingNotificationsInterface onRetrieveMissingNotifications){
public RetrieveMissingNotificationsAsyncTask(Context context, DisplayNotificationsFragment.Type type, String since_id, OnRetrieveMissingNotificationsInterface onRetrieveMissingNotifications) {
this.contextReference = new WeakReference<>(context);
this.since_id = since_id;
this.listener = onRetrieveMissingNotifications;
@ -59,7 +59,7 @@ public class RetrieveMissingNotificationsAsyncTask extends AsyncTask<Void, Void,
error = apiResponse.getError();
since_id = apiResponse.getSince_id();
notifications = apiResponse.getNotifications();
if( notifications != null && notifications.size() > 0) {
if (notifications != null && notifications.size() > 0) {
MainActivity.lastNotificationId = notifications.get(0).getId();
}
return null;
@ -67,7 +67,7 @@ public class RetrieveMissingNotificationsAsyncTask extends AsyncTask<Void, Void,
@Override
protected void onPostExecute(Void result) {
if( error == null)
if (error == null)
listener.onRetrieveMissingNotifications(notifications);
}
}

View File

@ -42,7 +42,7 @@ public class RetrieveNotificationChartsAsyncTask extends AsyncTask<Void, Void, V
private Date dateEnd;
private String status_id;
public RetrieveNotificationChartsAsyncTask(Context context, String status_id, Date dateIni, Date dateEnd, OnRetrieveNotificationChartsInterface onRetrieveNotificationChartsInterface){
public RetrieveNotificationChartsAsyncTask(Context context, String status_id, Date dateIni, Date dateEnd, OnRetrieveNotificationChartsInterface onRetrieveNotificationChartsInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveNotificationChartsInterface;
this.dateIni = dateIni;

View File

@ -38,7 +38,7 @@ public class RetrieveNotificationStatsAsyncTask extends AsyncTask<Void, Void, Vo
private WeakReference<Context> contextReference;
private StatisticsNotification statistics;
public RetrieveNotificationStatsAsyncTask(Context context, OnRetrieveNotificationStatsInterface onRetrieveNotificationStatsInterface){
public RetrieveNotificationStatsAsyncTask(Context context, OnRetrieveNotificationStatsInterface onRetrieveNotificationStatsInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveNotificationStatsInterface;
}

View File

@ -29,7 +29,6 @@ import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.interfaces.OnRetrieveNotificationsInterface;
/**
* Created by Thomas on 28/04/2017.
* Retrieves notifications on the instance
@ -47,7 +46,7 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
private boolean display;
private DisplayNotificationsFragment.Type type;
public RetrieveNotificationsAsyncTask(Context context, DisplayNotificationsFragment.Type type, boolean display, Account account, String max_id, OnRetrieveNotificationsInterface onRetrieveNotificationsInterface){
public RetrieveNotificationsAsyncTask(Context context, DisplayNotificationsFragment.Type type, boolean display, Account account, String max_id, OnRetrieveNotificationsInterface onRetrieveNotificationsInterface) {
this.contextReference = new WeakReference<>(context);
this.max_id = max_id;
this.listener = onRetrieveNotificationsInterface;
@ -60,7 +59,7 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
@Override
protected Void doInBackground(Void... params) {
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
API api;
if (account == null) {
api = new API(this.contextReference.get());
@ -73,7 +72,7 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
api = new API(this.contextReference.get(), account.getInstance(), account.getToken());
apiResponse = api.getNotificationsSince(type, max_id, display);
}
}else{
} else {
GNUAPI gnuapi;
if (account == null) {
gnuapi = new GNUAPI(this.contextReference.get());

View File

@ -43,7 +43,7 @@ public class RetrieveNotificationsCacheAsyncTask extends AsyncTask<Void, Void, V
private WeakReference<Context> contextReference;
private FilterNotifications filterNotifications;
public RetrieveNotificationsCacheAsyncTask(Context context, FilterNotifications filterNotifications, String max_id, OnRetrieveCacheNotificationsInterface onRetrieveNotificationsInterface){
public RetrieveNotificationsCacheAsyncTask(Context context, FilterNotifications filterNotifications, String max_id, OnRetrieveCacheNotificationsInterface onRetrieveNotificationsInterface) {
this.contextReference = new WeakReference<>(context);
this.max_id = max_id;
this.listener = onRetrieveNotificationsInterface;
@ -56,7 +56,7 @@ public class RetrieveNotificationsCacheAsyncTask extends AsyncTask<Void, Void, V
List<Notification> notifications = new NotificationCacheDAO(contextReference.get(), db).getNotificationsFromID(filterNotifications, max_id);
apiResponse = new APIResponse();
apiResponse.setNotifications(notifications);
if( notifications != null && notifications.size() > 0 ) {
if (notifications != null && notifications.size() > 0) {
apiResponse.setMax_id(notifications.get(notifications.size() - 1).getId());
}
return null;

View File

@ -38,12 +38,12 @@ public class RetrieveOpenCollectiveAsyncTask extends AsyncTask<Void, Void, Void>
private WeakReference<Context> contextReference;
private Type type;
public enum Type{
public enum Type {
BACKERS,
SPONSORS
}
public RetrieveOpenCollectiveAsyncTask(Context context, Type type, OnRetrieveRemoteAccountInterface onRetrieveRemoteAccountInterface){
public RetrieveOpenCollectiveAsyncTask(Context context, Type type, OnRetrieveRemoteAccountInterface onRetrieveRemoteAccountInterface) {
this.type = type;
this.listener = onRetrieveRemoteAccountInterface;
this.contextReference = new WeakReference<>(context);

View File

@ -38,15 +38,12 @@ import app.fedilab.android.interfaces.OnRetrievePeertubeInterface;
public class RetrievePeertubeChannelsAsyncTask extends AsyncTask<Void, Void, Void> {
private APIResponse apiResponse;
private OnRetrievePeertubeInterface listener;
private WeakReference<Context> contextReference;
public RetrievePeertubeChannelsAsyncTask(Context context, OnRetrievePeertubeInterface onRetrievePeertubeInterface){
public RetrievePeertubeChannelsAsyncTask(Context context, OnRetrievePeertubeInterface onRetrievePeertubeInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrievePeertubeInterface;
}

View File

@ -32,13 +32,11 @@ import app.fedilab.android.client.PeertubeAPI;
public class RetrievePeertubeInformationAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<Context> contextReference;
public static PeertubeInformation peertubeInformation;
public RetrievePeertubeInformationAsyncTask(Context context){
public RetrievePeertubeInformationAsyncTask(Context context) {
this.contextReference = new WeakReference<>(context);
}

View File

@ -40,7 +40,7 @@ public class RetrievePeertubeNotificationsAsyncTask extends AsyncTask<Void, Void
private OnRetrievePeertubeNotificationsInterface listener;
private WeakReference<Context> contextReference;
public RetrievePeertubeNotificationsAsyncTask(Context context, Account account, String max_id, OnRetrievePeertubeNotificationsInterface onRetrievePeertubeNotificationsInterface){
public RetrievePeertubeNotificationsAsyncTask(Context context, Account account, String max_id, OnRetrievePeertubeNotificationsInterface onRetrievePeertubeNotificationsInterface) {
this.contextReference = new WeakReference<>(context);
this.max_id = max_id;
this.listener = onRetrievePeertubeNotificationsInterface;
@ -51,11 +51,11 @@ public class RetrievePeertubeNotificationsAsyncTask extends AsyncTask<Void, Void
@Override
protected Void doInBackground(Void... params) {
PeertubeAPI api;
if( account == null) {
if (account == null) {
api = new PeertubeAPI(this.contextReference.get());
apiResponse = api.getNotifications(max_id);
}else {
if( this.contextReference.get() == null) {
} else {
if (this.contextReference.get() == null) {
apiResponse.setError(new Error());
return null;
}

View File

@ -36,7 +36,7 @@ public class RetrievePeertubeSearchAsyncTask extends AsyncTask<Void, Void, Void>
private OnRetrieveFeedsInterface listener;
private WeakReference<Context> contextReference;
public RetrievePeertubeSearchAsyncTask(Context context, String instance, String query, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
public RetrievePeertubeSearchAsyncTask(Context context, String instance, String query, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context);
this.query = query;
this.listener = onRetrieveFeedsInterface;

View File

@ -36,7 +36,6 @@ import app.fedilab.android.interfaces.OnRetrievePeertubeInterface;
public class RetrievePeertubeSingleAsyncTask extends AsyncTask<Void, Void, Void> {
private APIResponse apiResponse;
private String videoId;
private OnRetrievePeertubeInterface listener;
@ -44,8 +43,7 @@ public class RetrievePeertubeSingleAsyncTask extends AsyncTask<Void, Void, Void>
private String instanceName;
public RetrievePeertubeSingleAsyncTask(Context context, String instanceName, String videoId, OnRetrievePeertubeInterface onRetrievePeertubeInterface){
public RetrievePeertubeSingleAsyncTask(Context context, String instanceName, String videoId, OnRetrievePeertubeInterface onRetrievePeertubeInterface) {
this.contextReference = new WeakReference<>(context);
this.videoId = videoId;
this.listener = onRetrievePeertubeInterface;
@ -53,20 +51,19 @@ public class RetrievePeertubeSingleAsyncTask extends AsyncTask<Void, Void, Void>
}
@Override
protected Void doInBackground(Void... params) {
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
API api = new API(this.contextReference.get());
apiResponse = api.getSinglePeertube(this.instanceName, videoId);
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
apiResponse = peertubeAPI.getSinglePeertube(this.instanceName, videoId, token);
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
String rate = new PeertubeAPI(this.contextReference.get()).getRating(videoId);
if( rate != null)
if (rate != null)
apiResponse.getPeertubes().get(0).setMyRating(rate);
}
}

View File

@ -32,7 +32,6 @@ import app.fedilab.android.interfaces.OnRetrievePeertubeInterface;
public class RetrievePeertubeSingleCommentsAsyncTask extends AsyncTask<Void, Void, Void> {
private APIResponse apiResponse;
private String videoId;
private OnRetrievePeertubeInterface listener;
@ -40,8 +39,7 @@ public class RetrievePeertubeSingleCommentsAsyncTask extends AsyncTask<Void, Voi
private String instanceName;
public RetrievePeertubeSingleCommentsAsyncTask(Context context, String instanceName, String videoId, OnRetrievePeertubeInterface onRetrievePeertubeInterface){
public RetrievePeertubeSingleCommentsAsyncTask(Context context, String instanceName, String videoId, OnRetrievePeertubeInterface onRetrievePeertubeInterface) {
this.contextReference = new WeakReference<>(context);
this.videoId = videoId;
this.listener = onRetrievePeertubeInterface;
@ -49,7 +47,6 @@ public class RetrievePeertubeSingleCommentsAsyncTask extends AsyncTask<Void, Voi
}
@Override
protected Void doInBackground(Void... params) {
API api = new API(this.contextReference.get());

View File

@ -41,7 +41,7 @@ public class RetrieveRelationshipAsyncTask extends AsyncTask<Void, Void, Void> {
private Error error;
private WeakReference<Context> contextReference;
public RetrieveRelationshipAsyncTask(Context context, String accountId, OnRetrieveRelationshipInterface onRetrieveRelationshipInterface){
public RetrieveRelationshipAsyncTask(Context context, String accountId, OnRetrieveRelationshipInterface onRetrieveRelationshipInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveRelationshipInterface;
this.accountId = accountId;
@ -54,11 +54,11 @@ public class RetrieveRelationshipAsyncTask extends AsyncTask<Void, Void, Void> {
API api = new API(this.contextReference.get());
relationship = api.getRelationship(accountId);
error = api.getError();
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
relationship = gnuapi.getRelationship(accountId);
error = gnuapi.getError();
}else {
} else {
PeertubeAPI api = new PeertubeAPI(this.contextReference.get());
relationship = new Relationship();
relationship.setFollowing(api.isFollowing(accountId));

View File

@ -39,7 +39,7 @@ public class RetrieveRelationshipQuickReplyAsyncTask extends AsyncTask<Void, Voi
private Error error;
private WeakReference<Context> contextReference;
public RetrieveRelationshipQuickReplyAsyncTask(Context context, app.fedilab.android.client.Entities.Status status, OnRetrieveRelationshipQuickReplyInterface onRetrieveRelationshipQuickReplyInterface){
public RetrieveRelationshipQuickReplyAsyncTask(Context context, app.fedilab.android.client.Entities.Status status, OnRetrieveRelationshipQuickReplyInterface onRetrieveRelationshipQuickReplyInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveRelationshipQuickReplyInterface;
this.status = status;
@ -50,7 +50,7 @@ public class RetrieveRelationshipQuickReplyAsyncTask extends AsyncTask<Void, Voi
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
API api = new API(this.contextReference.get());
relationship = api.getRelationship(status.getReblog()!=null?status.getReblog().getAccount().getId():status.getAccount().getId());
relationship = api.getRelationship(status.getReblog() != null ? status.getReblog().getAccount().getId() : status.getAccount().getId());
error = api.getError();
}
return null;

View File

@ -41,13 +41,13 @@ public class RetrieveRemoteDataAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<Context> contextReference;
public RetrieveRemoteDataAsyncTask(Context context, String username, String instance, OnRetrieveRemoteAccountInterface onRetrieveRemoteAccountInterface){
public RetrieveRemoteDataAsyncTask(Context context, String username, String instance, OnRetrieveRemoteAccountInterface onRetrieveRemoteAccountInterface) {
this.url = Helper.instanceWithProtocol(context, instance) + "/@" + username;
this.listener = onRetrieveRemoteAccountInterface;
this.contextReference = new WeakReference<>(context);
}
public RetrieveRemoteDataAsyncTask(Context context, String url, OnRetrieveRemoteAccountInterface onRetrieveRemoteAccountInterface){
public RetrieveRemoteDataAsyncTask(Context context, String url, OnRetrieveRemoteAccountInterface onRetrieveRemoteAccountInterface) {
this.url = url;
this.listener = onRetrieveRemoteAccountInterface;
this.contextReference = new WeakReference<>(context);
@ -57,7 +57,7 @@ public class RetrieveRemoteDataAsyncTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
API api = new API(this.contextReference.get());
APIResponse apiResponse = api.search(this.url);
if( apiResponse.getResults() != null)
if (apiResponse.getResults() != null)
results = apiResponse.getResults();
return null;
}

View File

@ -50,7 +50,7 @@ public class RetrieveScheduledTootsAsyncTask extends AsyncTask<Void, Void, Void>
private WeakReference<Context> contextReference;
private DisplayScheduledTootsFragment.typeOfSchedule type;
public RetrieveScheduledTootsAsyncTask(Context context, DisplayScheduledTootsFragment.typeOfSchedule type, OnRetrieveScheduledTootsInterface onRetrieveScheduledTootsInterface){
public RetrieveScheduledTootsAsyncTask(Context context, DisplayScheduledTootsFragment.typeOfSchedule type, OnRetrieveScheduledTootsInterface onRetrieveScheduledTootsInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveScheduledTootsInterface;
this.type = type;
@ -60,36 +60,36 @@ public class RetrieveScheduledTootsAsyncTask extends AsyncTask<Void, Void, Void>
protected Void doInBackground(Void... params) {
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
//Retrieves job asked by the user
if( type == DisplayScheduledTootsFragment.typeOfSchedule.TOOT)
if (type == DisplayScheduledTootsFragment.typeOfSchedule.TOOT)
storedStatuses = new StatusStoredDAO(this.contextReference.get(), db).getAllScheduled();
else if(type == DisplayScheduledTootsFragment.typeOfSchedule.BOOST )
else if (type == DisplayScheduledTootsFragment.typeOfSchedule.BOOST)
storedStatuses = new BoostScheduleDAO(this.contextReference.get(), db).getAllScheduled();
//Retrieves real jobs still waiting
Set<JobRequest> jobRequests = null;
if( type == DisplayScheduledTootsFragment.typeOfSchedule.TOOT)
if (type == DisplayScheduledTootsFragment.typeOfSchedule.TOOT)
jobRequests = JobManager.instance().getAllJobRequestsForTag(ScheduledTootsSyncJob.SCHEDULED_TOOT);
else if(type == DisplayScheduledTootsFragment.typeOfSchedule.BOOST )
else if (type == DisplayScheduledTootsFragment.typeOfSchedule.BOOST)
jobRequests = JobManager.instance().getAllJobRequestsForTag(ScheduledBoostsSyncJob.SCHEDULED_BOOST);
int[] jobIds;
if( jobRequests != null && jobRequests.size() > 0 ){
if (jobRequests != null && jobRequests.size() > 0) {
int i = 0;
jobIds = new int[jobRequests.size()];
for(JobRequest jobRequest : jobRequests){
for (JobRequest jobRequest : jobRequests) {
jobIds[i] = jobRequest.getJobId();
i++;
}
}else{
} else {
jobIds = new int[]{};
}
if( storedStatuses != null && storedStatuses.size() > 0 ){
for(StoredStatus ss: storedStatuses){
if (!Helper.isJobPresent(jobIds, ss.getJobId())){
if (storedStatuses != null && storedStatuses.size() > 0) {
for (StoredStatus ss : storedStatuses) {
if (!Helper.isJobPresent(jobIds, ss.getJobId())) {
//JobId is fixed to -1 which means an error occured (it was never sent)
if( type == DisplayScheduledTootsFragment.typeOfSchedule.TOOT)
new StatusStoredDAO(this.contextReference.get(), db).updateJobId(ss.getId(),-1);
else if(type == DisplayScheduledTootsFragment.typeOfSchedule.BOOST )
new BoostScheduleDAO(this.contextReference.get(), db).updateJobId(ss.getId(),-1);
if (type == DisplayScheduledTootsFragment.typeOfSchedule.TOOT)
new StatusStoredDAO(this.contextReference.get(), db).updateJobId(ss.getId(), -1);
else if (type == DisplayScheduledTootsFragment.typeOfSchedule.BOOST)
new BoostScheduleDAO(this.contextReference.get(), db).updateJobId(ss.getId(), -1);
}
}
//Lets time to update db before dispaying

View File

@ -37,14 +37,14 @@ public class RetrieveSearchAccountsAsyncTask extends AsyncTask<Void, Void, Void>
private WeakReference<Context> contextReference;
private boolean following;
public RetrieveSearchAccountsAsyncTask(Context context, String query, OnRetrieveSearcAccountshInterface onRetrieveSearcAccountshInterface){
public RetrieveSearchAccountsAsyncTask(Context context, String query, OnRetrieveSearcAccountshInterface onRetrieveSearcAccountshInterface) {
this.contextReference = new WeakReference<>(context);
this.query = query;
this.listener = onRetrieveSearcAccountshInterface;
this.following = false;
}
public RetrieveSearchAccountsAsyncTask(Context context, String query, boolean following, OnRetrieveSearcAccountshInterface onRetrieveSearcAccountshInterface){
public RetrieveSearchAccountsAsyncTask(Context context, String query, boolean following, OnRetrieveSearcAccountshInterface onRetrieveSearcAccountshInterface) {
this.contextReference = new WeakReference<>(context);
this.query = query;
this.listener = onRetrieveSearcAccountshInterface;
@ -54,7 +54,7 @@ public class RetrieveSearchAccountsAsyncTask extends AsyncTask<Void, Void, Void>
@Override
protected Void doInBackground(Void... params) {
API api = new API(this.contextReference.get());
if( !following)
if (!following)
apiResponse = api.searchAccounts(query, 20);
else
apiResponse = new API(contextReference.get()).searchAccounts(query, 20, true);
@ -63,7 +63,7 @@ public class RetrieveSearchAccountsAsyncTask extends AsyncTask<Void, Void, Void>
@Override
protected void onPostExecute(Void result) {
if( !following)
if (!following)
listener.onRetrieveSearchAccounts(apiResponse);
else
listener.onRetrieveContact(apiResponse);

View File

@ -48,20 +48,20 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> {
private API.searchType type;
private String max_id;
public RetrieveSearchAsyncTask(Context context, String query, OnRetrieveSearchInterface onRetrieveSearchInterface){
public RetrieveSearchAsyncTask(Context context, String query, OnRetrieveSearchInterface onRetrieveSearchInterface) {
this.contextReference = new WeakReference<>(context);
this.query = query;
this.listener = onRetrieveSearchInterface;
}
public RetrieveSearchAsyncTask(Context context, String query, boolean tagsOnly, OnRetrieveSearchInterface onRetrieveSearchInterface){
public RetrieveSearchAsyncTask(Context context, String query, boolean tagsOnly, OnRetrieveSearchInterface onRetrieveSearchInterface) {
this.contextReference = new WeakReference<>(context);
this.query = query;
this.listener = onRetrieveSearchInterface;
this.tagsOnly = tagsOnly;
}
public RetrieveSearchAsyncTask(Context context, String query, API.searchType searchType, String max_id, OnRetrieveSearchInterface onRetrieveSearchInterface){
public RetrieveSearchAsyncTask(Context context, String query, API.searchType searchType, String max_id, OnRetrieveSearchInterface onRetrieveSearchInterface) {
this.contextReference = new WeakReference<>(context);
this.query = query;
this.listener = onRetrieveSearchInterface;
@ -76,39 +76,39 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
API api = new API(this.contextReference.get());
String[] split = query.trim().split("@");
if( split.length > 1 ){
if (split.length > 1) {
String domain;
String username;
if( split.length == 2){
username = split[0];
domain = split[1];
}else{
username = split[1];
domain = split[2];
}
if( domain != null && username != null){
InstanceNodeInfo node = api.getNodeInfo(domain);
String url = null;
if( node != null && node.getName() != null){
switch (node.getName().trim()){
case "MASTODON":
url = "https://" + domain + "/@" + username;
break;
case "PEERTUBE":
url = "https://" + domain + "/accounts/" + username;
break;
case "PIXELFED":
url = "https://" + domain + "/" + username;
break;
case "GNU":
url = "https://" + domain + "/profile/" + username;
break;
}
}
if( url != null)
query = url;
}
String domain;
String username;
if (split.length == 2) {
username = split[0];
domain = split[1];
} else {
username = split[1];
domain = split[2];
}
if (domain != null && username != null) {
InstanceNodeInfo node = api.getNodeInfo(domain);
String url = null;
if (node != null && node.getName() != null) {
switch (node.getName().trim()) {
case "MASTODON":
url = "https://" + domain + "/@" + username;
break;
case "PEERTUBE":
url = "https://" + domain + "/accounts/" + username;
break;
case "PIXELFED":
url = "https://" + domain + "/" + username;
break;
case "GNU":
url = "https://" + domain + "/profile/" + username;
break;
}
}
if (url != null)
query = url;
}
}
@ -141,7 +141,7 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> {
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
apiResponse = gnuapi.search(query);
}
}else{
} else {
API api = new API(this.contextReference.get());
apiResponse = api.search2(query, type, max_id);
}

View File

@ -17,7 +17,9 @@ package app.fedilab.android.asynctasks;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import app.fedilab.android.client.Entities.Statistics;
import app.fedilab.android.interfaces.OnRetrieveStatsInterface;
import app.fedilab.android.sqlite.Sqlite;
@ -36,7 +38,7 @@ public class RetrieveStatsAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<Context> contextReference;
private Statistics statistics;
public RetrieveStatsAsyncTask(Context context, OnRetrieveStatsInterface onRetrieveStatsInterface){
public RetrieveStatsAsyncTask(Context context, OnRetrieveStatsInterface onRetrieveStatsInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveStatsInterface;
}

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