parent
68d0862008
commit
558adc6936
|
@ -9,6 +9,7 @@ import android.util.Log;
|
||||||
import org.joinmastodon.android.api.ObjectValidationException;
|
import org.joinmastodon.android.api.ObjectValidationException;
|
||||||
import org.joinmastodon.android.api.session.AccountSession;
|
import org.joinmastodon.android.api.session.AccountSession;
|
||||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
|
import org.joinmastodon.android.fragments.ComposeFragment;
|
||||||
import org.joinmastodon.android.fragments.HomeFragment;
|
import org.joinmastodon.android.fragments.HomeFragment;
|
||||||
import org.joinmastodon.android.fragments.ProfileFragment;
|
import org.joinmastodon.android.fragments.ProfileFragment;
|
||||||
import org.joinmastodon.android.fragments.SplashFragment;
|
import org.joinmastodon.android.fragments.SplashFragment;
|
||||||
|
@ -56,6 +57,8 @@ public class MainActivity extends FragmentStackActivity{
|
||||||
if(intent.getBooleanExtra("fromNotification", false) && intent.hasExtra("notification")){
|
if(intent.getBooleanExtra("fromNotification", false) && intent.hasExtra("notification")){
|
||||||
Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification"));
|
Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification"));
|
||||||
showFragmentForNotification(notification, session.getID());
|
showFragmentForNotification(notification, session.getID());
|
||||||
|
}else if(intent.getBooleanExtra("compose", false)){
|
||||||
|
showCompose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,6 +94,8 @@ public class MainActivity extends FragmentStackActivity{
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
showFragmentClearingBackStack(fragment);
|
showFragmentClearingBackStack(fragment);
|
||||||
}
|
}
|
||||||
|
}else if(intent.getBooleanExtra("compose", false)){
|
||||||
|
showCompose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,4 +120,15 @@ public class MainActivity extends FragmentStackActivity{
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
showFragment(fragment);
|
showFragment(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showCompose(){
|
||||||
|
AccountSession session=AccountSessionManager.getInstance().getLastActiveAccount();
|
||||||
|
if(session==null || !session.activated)
|
||||||
|
return;
|
||||||
|
ComposeFragment compose=new ComposeFragment();
|
||||||
|
Bundle composeArgs=new Bundle();
|
||||||
|
composeArgs.putString("account", session.getID());
|
||||||
|
compose.setArguments(composeArgs);
|
||||||
|
showFragment(compose);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,22 @@ package org.joinmastodon.android.api.session;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.ShortcutInfo;
|
||||||
|
import android.content.pm.ShortcutManager;
|
||||||
|
import android.graphics.drawable.Icon;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.BuildConfig;
|
||||||
import org.joinmastodon.android.E;
|
import org.joinmastodon.android.E;
|
||||||
|
import org.joinmastodon.android.MainActivity;
|
||||||
import org.joinmastodon.android.MastodonApp;
|
import org.joinmastodon.android.MastodonApp;
|
||||||
import org.joinmastodon.android.R;
|
import org.joinmastodon.android.R;
|
||||||
import org.joinmastodon.android.api.MastodonAPIController;
|
import org.joinmastodon.android.api.MastodonAPIController;
|
||||||
|
@ -90,6 +97,7 @@ public class AccountSessionManager{
|
||||||
}
|
}
|
||||||
lastActiveAccountID=prefs.getString("lastActiveAccount", null);
|
lastActiveAccountID=prefs.getString("lastActiveAccount", null);
|
||||||
MastodonAPIController.runInBackground(()->readInstanceInfo(domains));
|
MastodonAPIController.runInBackground(()->readInstanceInfo(domains));
|
||||||
|
maybeUpdateShortcuts();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAccount(Instance instance, Token token, Account self, Application app, boolean active){
|
public void addAccount(Instance instance, Token token, Account self, Application app, boolean active){
|
||||||
|
@ -102,6 +110,7 @@ public class AccountSessionManager{
|
||||||
if(PushSubscriptionManager.arePushNotificationsAvailable()){
|
if(PushSubscriptionManager.arePushNotificationsAvailable()){
|
||||||
session.getPushSubscriptionManager().registerAccountForPush(null);
|
session.getPushSubscriptionManager().registerAccountForPush(null);
|
||||||
}
|
}
|
||||||
|
maybeUpdateShortcuts();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void writeAccountsFile(){
|
public synchronized void writeAccountsFile(){
|
||||||
|
@ -181,6 +190,7 @@ public class AccountSessionManager{
|
||||||
NotificationManager nm=MastodonApp.context.getSystemService(NotificationManager.class);
|
NotificationManager nm=MastodonApp.context.getSystemService(NotificationManager.class);
|
||||||
nm.deleteNotificationChannelGroup(id);
|
nm.deleteNotificationChannelGroup(id);
|
||||||
}
|
}
|
||||||
|
maybeUpdateShortcuts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -395,6 +405,29 @@ public class AccountSessionManager{
|
||||||
writeAccountsFile();
|
writeAccountsFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void maybeUpdateShortcuts(){
|
||||||
|
if(Build.VERSION.SDK_INT<26)
|
||||||
|
return;
|
||||||
|
ShortcutManager sm=MastodonApp.context.getSystemService(ShortcutManager.class);
|
||||||
|
if((sm.getDynamicShortcuts().isEmpty() || BuildConfig.DEBUG) && !sessions.isEmpty()){
|
||||||
|
// There are no shortcuts, but there are accounts. Add a compose shortcut.
|
||||||
|
ShortcutInfo info=new ShortcutInfo.Builder(MastodonApp.context, "compose")
|
||||||
|
.setActivity(ComponentName.createRelative(MastodonApp.context, MainActivity.class.getName()))
|
||||||
|
.setShortLabel(MastodonApp.context.getString(R.string.new_post))
|
||||||
|
.setIcon(Icon.createWithResource(MastodonApp.context, R.mipmap.ic_shortcut_compose))
|
||||||
|
.setIntent(new Intent(MastodonApp.context, MainActivity.class)
|
||||||
|
.setAction(Intent.ACTION_MAIN)
|
||||||
|
.putExtra("compose", true))
|
||||||
|
.build();
|
||||||
|
sm.setDynamicShortcuts(Collections.singletonList(info));
|
||||||
|
}else if(sessions.isEmpty()){
|
||||||
|
// There are shortcuts, but no accounts. Disable existing shortcuts.
|
||||||
|
sm.disableShortcuts(Collections.singletonList("compose"), MastodonApp.context.getString(R.string.err_not_logged_in));
|
||||||
|
}else{
|
||||||
|
sm.enableShortcuts(Collections.singletonList("compose"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class SessionsStorageWrapper{
|
private static class SessionsStorageWrapper{
|
||||||
public List<AccountSession> accounts;
|
public List<AccountSession> accounts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<vector android:height="108dp"
|
||||||
|
android:viewportHeight="48" android:viewportWidth="48"
|
||||||
|
android:width="108dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<group android:translateX="12" android:translateY="12">
|
||||||
|
<path android:fillColor="@color/shortcut_icon_foreground" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
|
||||||
|
</group>
|
||||||
|
</vector>
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background>
|
||||||
|
<shape>
|
||||||
|
<solid android:color="@color/shortcut_icon_background"/>
|
||||||
|
<size android:width="108dp" android:height="108dp"/>
|
||||||
|
</shape>
|
||||||
|
</background>
|
||||||
|
<foreground android:drawable="@drawable/ic_compose_foreground"/>
|
||||||
|
</adaptive-icon>
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="shortcut_icon_background">@color/gray_700</color>
|
||||||
|
<color name="shortcut_icon_foreground">@color/primary_600</color>
|
||||||
|
</resources>
|
|
@ -93,4 +93,7 @@
|
||||||
|
|
||||||
<color name="favorite_selected">@color/warning_500</color>
|
<color name="favorite_selected">@color/warning_500</color>
|
||||||
<color name="boost_selected">@color/primary_500</color>
|
<color name="boost_selected">@color/primary_500</color>
|
||||||
|
|
||||||
|
<color name="shortcut_icon_background">@color/gray_100</color>
|
||||||
|
<color name="shortcut_icon_foreground">@color/primary_700</color>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue