Some fixes

This commit is contained in:
Thomas 2022-07-30 18:47:30 +02:00
parent 18bc812cf1
commit 2553b4835b
9 changed files with 72 additions and 49 deletions

View File

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

View File

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

View File

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

View File

@ -1298,13 +1298,19 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
@Override
public void afterTextChanged(Editable s) {
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())));
buttonVisibility(holder);
} else if (currentLength > max_car) {
buttonVisibility(holder);
holder.binding.contentSpoiler.setText(s.delete(cPosition, cPosition + 1));
}
}*/
statusList.get(holder.getBindingAdapterPosition()).spoiler_text = s.toString();
if (s.toString().trim().length() < 2) {
buttonVisibility(holder);

View File

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

View File

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

View File

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

View File

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

View File

@ -991,6 +991,7 @@
<string name="my_account">My account</string>
<string name="set_your_max_char_count">Set your max char count</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">
<!-- Smiles -->