pull/307/head
Thomas 2 years ago
parent 18bc812cf1
commit 2553b4835b

@ -24,6 +24,7 @@ android {
} }
} }
compileOptions { compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
@ -128,4 +129,5 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1' // debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
} }

@ -479,7 +479,9 @@ public class ProfileActivity extends BaseActivity {
* This methode is called to update the view once an action has been performed * This methode is called to update the view once an action has been performed
*/ */
private void updateAccount() { private void updateAccount() {
if (currentAccount == null || account == null) {
return;
}
//The value for account is from same server so id can be used //The value for account is from same server so id can be used
if (account.id.equals(currentAccount.user_id)) { if (account.id.equals(currentAccount.user_id)) {
binding.accountFollow.setVisibility(View.GONE); binding.accountFollow.setVisibility(View.GONE);

@ -207,34 +207,37 @@ public class WebviewConnectActivity extends BaseActivity {
String scope = requestedAdmin ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES; String scope = requestedAdmin ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES;
oauthVM.createToken(currentInstanceLogin, "authorization_code", client_idLogin, client_secretLogin, Helper.REDIRECT_CONTENT_WEB, scope, code) oauthVM.createToken(currentInstanceLogin, "authorization_code", client_idLogin, client_secretLogin, Helper.REDIRECT_CONTENT_WEB, scope, code)
.observe(WebviewConnectActivity.this, tokenObj -> { .observe(WebviewConnectActivity.this, tokenObj -> {
Account account = new Account(); if (tokenObj != null) {
account.client_id = client_idLogin; Account account = new Account();
account.client_secret = client_secretLogin; account.client_id = client_idLogin;
account.token = tokenObj.token_type + " " + tokenObj.access_token; account.client_secret = client_secretLogin;
account.api = apiLogin; account.token = tokenObj.token_type + " " + tokenObj.access_token;
account.software = softwareLogin; account.api = apiLogin;
account.instance = currentInstanceLogin; account.software = softwareLogin;
//API call to retrieve account information for the new token account.instance = currentInstanceLogin;
AccountsVM accountsVM = new ViewModelProvider(WebviewConnectActivity.this).get(AccountsVM.class); //API call to retrieve account information for the new token
accountsVM.getConnectedAccount(currentInstanceLogin, account.token).observe(WebviewConnectActivity.this, mastodonAccount -> { AccountsVM accountsVM = new ViewModelProvider(WebviewConnectActivity.this).get(AccountsVM.class);
if (mastodonAccount != null) { accountsVM.getConnectedAccount(currentInstanceLogin, account.token).observe(WebviewConnectActivity.this, mastodonAccount -> {
account.mastodon_account = mastodonAccount; if (mastodonAccount != null) {
account.user_id = mastodonAccount.id; account.mastodon_account = mastodonAccount;
//We check if user have really moderator rights account.user_id = mastodonAccount.id;
if (requestedAdmin) { //We check if user have really moderator rights
AdminVM adminVM = new ViewModelProvider(WebviewConnectActivity.this).get(AdminVM.class); if (requestedAdmin) {
adminVM.getAccount(account.instance, account.token, account.user_id).observe(WebviewConnectActivity.this, adminAccount -> { AdminVM adminVM = new ViewModelProvider(WebviewConnectActivity.this).get(AdminVM.class);
account.admin = adminAccount != null; adminVM.getAccount(account.instance, account.token, account.user_id).observe(WebviewConnectActivity.this, adminAccount -> {
account.admin = adminAccount != null;
proceedLogin(WebviewConnectActivity.this, account);
});
} else {
proceedLogin(WebviewConnectActivity.this, account); proceedLogin(WebviewConnectActivity.this, account);
}); }
} else { } else {
proceedLogin(WebviewConnectActivity.this, account); Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
} }
} else { });
Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); } else {
} Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_token), Toasty.LENGTH_SHORT).show();
}
});
}); });
return true; return true;
} else { } else {

@ -1298,13 +1298,19 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
int currentLength = MastodonHelper.countLength(holder); int currentLength = MastodonHelper.countLength(holder);
if (currentLength > max_car + 1) { int max_car = MastodonHelper.getInstanceMaxChars(context);
if (currentLength > max_car) {
holder.binding.characterCount.setTextColor(Color.RED);
} else {
holder.binding.characterCount.setTextColor(holder.binding.content.getTextColors());
}
/*if (currentLength > max_car + 1) {
holder.binding.contentSpoiler.setText(s.delete(max_car - holder.binding.content.getText().length(), (currentLength - holder.binding.content.getText().length()))); holder.binding.contentSpoiler.setText(s.delete(max_car - holder.binding.content.getText().length(), (currentLength - holder.binding.content.getText().length())));
buttonVisibility(holder); buttonVisibility(holder);
} else if (currentLength > max_car) { } else if (currentLength > max_car) {
buttonVisibility(holder); buttonVisibility(holder);
holder.binding.contentSpoiler.setText(s.delete(cPosition, cPosition + 1)); holder.binding.contentSpoiler.setText(s.delete(cPosition, cPosition + 1));
} }*/
statusList.get(holder.getBindingAdapterPosition()).spoiler_text = s.toString(); statusList.get(holder.getBindingAdapterPosition()).spoiler_text = s.toString();
if (s.toString().trim().length() < 2) { if (s.toString().trim().length() < 2) {
buttonVisibility(holder); buttonVisibility(holder);

@ -37,12 +37,12 @@ import androidx.preference.PreferenceManager;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition; import com.bumptech.glide.request.transition.Transition;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.upstream.DefaultDataSource;
import com.google.android.exoplayer2.util.Util;
import java.util.Timer; import java.util.Timer;
@ -61,7 +61,7 @@ import app.fedilab.android.webview.FedilabWebViewClient;
public class FragmentMedia extends Fragment { public class FragmentMedia extends Fragment {
private SimpleExoPlayer player; private ExoPlayer player;
private Timer timer; private Timer timer;
private String url; private String url;
private boolean canSwipe; private boolean canSwipe;
@ -261,26 +261,26 @@ public class FragmentMedia extends Fragment {
binding.mediaVideo.setVisibility(View.VISIBLE); binding.mediaVideo.setVisibility(View.VISIBLE);
Uri uri = Uri.parse(url); Uri uri = Uri.parse(url);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
String userAgent = sharedpreferences.getString(getString(R.string.SET_CUSTOM_USER_AGENT), Helper.USER_AGENT);
int video_cache = sharedpreferences.getInt(getString(R.string.SET_VIDEO_CACHE), Helper.DEFAULT_VIDEO_CACHE_MB); int video_cache = sharedpreferences.getInt(getString(R.string.SET_VIDEO_CACHE), Helper.DEFAULT_VIDEO_CACHE_MB);
ProgressiveMediaSource videoSource; ProgressiveMediaSource videoSource;
MediaItem mediaItem = new MediaItem.Builder().setUri(uri).build();
if (video_cache == 0) { if (video_cache == 0) {
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(requireActivity(), DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(requireActivity());
Util.getUserAgent(requireActivity(), userAgent), null);
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory) videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(uri); .createMediaSource(mediaItem);
} else { } else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(requireActivity()); CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(requireActivity());
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory) videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(uri); .createMediaSource(mediaItem);
} }
player = new SimpleExoPlayer.Builder(requireActivity()).build(); player = new ExoPlayer.Builder(requireActivity()).build();
if (type.equalsIgnoreCase("gifv")) if (type.equalsIgnoreCase("gifv"))
player.setRepeatMode(Player.REPEAT_MODE_ONE); player.setRepeatMode(Player.REPEAT_MODE_ONE);
binding.mediaVideo.setPlayer(player); binding.mediaVideo.setPlayer(player);
binding.loader.setVisibility(View.GONE); binding.loader.setVisibility(View.GONE);
binding.mediaPicture.setVisibility(View.GONE); binding.mediaPicture.setVisibility(View.GONE);
player.prepare(videoSource); player.setMediaSource(videoSource);
player.prepare();
player.setPlayWhenReady(true); player.setPlayWhenReady(true);
} }

@ -137,7 +137,7 @@ public class FragmentMastodonConversation extends Fragment {
} }
}); });
binding.swipeContainer.setOnRefreshListener(() -> { binding.swipeContainer.setOnRefreshListener(() -> {
if (this.conversations.size() > 0) { if (this.conversations != null && this.conversations.size() > 0) {
binding.swipeContainer.setRefreshing(true); binding.swipeContainer.setRefreshing(true);
max_id = null; max_id = null;
flagLoading = false; flagLoading = false;

@ -61,6 +61,7 @@ import app.fedilab.android.ui.drawer.StatusAdapter;
import app.fedilab.android.viewmodel.mastodon.AccountsVM; import app.fedilab.android.viewmodel.mastodon.AccountsVM;
import app.fedilab.android.viewmodel.mastodon.SearchVM; import app.fedilab.android.viewmodel.mastodon.SearchVM;
import app.fedilab.android.viewmodel.mastodon.TimelinesVM; import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
import es.dmoral.toasty.Toasty;
public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.FetchMoreCallBack { public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.FetchMoreCallBack {
@ -809,19 +810,27 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class); SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class);
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, search.trim(), null, null, false, true, false, 0, null, null, MastodonHelper.STATUSES_PER_CALL) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, search.trim(), null, null, false, true, false, 0, null, null, MastodonHelper.STATUSES_PER_CALL)
.observe(getViewLifecycleOwner(), results -> { .observe(getViewLifecycleOwner(), results -> {
Statuses statuses = new Statuses(); if (results != null) {
statuses.statuses = results.statuses; Statuses statuses = new Statuses();
statuses.pagination = new Pagination(); statuses.statuses = results.statuses;
initializeStatusesCommonView(statuses); statuses.pagination = new Pagination();
initializeStatusesCommonView(statuses);
} else {
Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_LONG).show();
}
}); });
} else if (searchCache != null) { } else if (searchCache != null) {
SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class); SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class);
searchVM.searchCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, searchCache.trim()) searchVM.searchCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, searchCache.trim())
.observe(getViewLifecycleOwner(), results -> { .observe(getViewLifecycleOwner(), results -> {
Statuses statuses = new Statuses(); if (results != null) {
statuses.statuses = results.statuses; Statuses statuses = new Statuses();
statuses.pagination = new Pagination(); statuses.statuses = results.statuses;
initializeStatusesCommonView(statuses); statuses.pagination = new Pagination();
initializeStatusesCommonView(statuses);
} else {
Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_LONG).show();
}
}); });
} else if (timelineType == Timeline.TimeLineEnum.FAVOURITE_TIMELINE) { } else if (timelineType == Timeline.TimeLineEnum.FAVOURITE_TIMELINE) {
if (direction == null) { if (direction == null) {

@ -108,7 +108,7 @@ public class FedilabPageAdapter extends FragmentStatePagerAdapter {
} else if (pinnedTimeline.type == Timeline.TimeLineEnum.TAG) { } else if (pinnedTimeline.type == Timeline.TimeLineEnum.TAG) {
bundle.putSerializable(Helper.ARG_TAG_TIMELINE, pinnedTimeline.tagTimeline); bundle.putSerializable(Helper.ARG_TAG_TIMELINE, pinnedTimeline.tagTimeline);
} else if (pinnedTimeline.type == Timeline.TimeLineEnum.REMOTE) { } else if (pinnedTimeline.type == Timeline.TimeLineEnum.REMOTE) {
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinnedTimeline); bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinned);
} }
} }

@ -991,6 +991,7 @@
<string name="my_account">My account</string> <string name="my_account">My account</string>
<string name="set_your_max_char_count">Set your max char count</string> <string name="set_your_max_char_count">Set your max char count</string>
<string name="release_notes">Release notes</string> <string name="release_notes">Release notes</string>
<string name="toast_token">The app failed to get a token</string>
<string-array name="photo_editor_emoji" translatable="false"> <string-array name="photo_editor_emoji" translatable="false">
<!-- Smiles --> <!-- Smiles -->

Loading…
Cancel
Save