|
|
|
@ -79,6 +79,7 @@ import androidx.fragment.app.Fragment;
|
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
|
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
|
|
|
|
import androidx.multidex.BuildConfig;
|
|
|
|
|
import androidx.navigation.NavController;
|
|
|
|
|
import androidx.navigation.Navigation;
|
|
|
|
|
import androidx.navigation.ui.AppBarConfiguration;
|
|
|
|
@ -220,24 +221,34 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|
|
|
|
private final BroadcastReceiver broadcast_error_message = new BroadcastReceiver() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(android.content.Context context, Intent intent) {
|
|
|
|
|
Bundle b = intent.getExtras();
|
|
|
|
|
if (b != null) {
|
|
|
|
|
if (b.getBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, false)) {
|
|
|
|
|
String errorMessage = b.getString(Helper.RECEIVE_ERROR_MESSAGE);
|
|
|
|
|
StatusDraft statusDraft = (StatusDraft) b.getSerializable(Helper.ARG_STATUS_DRAFT);
|
|
|
|
|
Snackbar snackbar = Snackbar.make(binding.getRoot(), errorMessage, 5000);
|
|
|
|
|
View snackbarView = snackbar.getView();
|
|
|
|
|
TextView textView = snackbarView.findViewById(com.google.android.material.R.id.snackbar_text);
|
|
|
|
|
textView.setMaxLines(5);
|
|
|
|
|
snackbar
|
|
|
|
|
.setAction(getString(R.string.open_draft), view -> {
|
|
|
|
|
Intent intentCompose = new Intent(context, ComposeActivity.class);
|
|
|
|
|
intentCompose.putExtra(Helper.ARG_STATUS_DRAFT, statusDraft);
|
|
|
|
|
intentCompose.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
context.startActivity(intentCompose);
|
|
|
|
|
})
|
|
|
|
|
.show();
|
|
|
|
|
}
|
|
|
|
|
Bundle args = intent.getExtras();
|
|
|
|
|
if (args != null) {
|
|
|
|
|
long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
|
|
|
|
|
new CachedBundle(BaseMainActivity.this).getBundle(bundleId, currentAccount, bundle -> {
|
|
|
|
|
if (bundle.getBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, false)) {
|
|
|
|
|
String errorMessage = bundle.getString(Helper.RECEIVE_ERROR_MESSAGE);
|
|
|
|
|
StatusDraft statusDraft = (StatusDraft) bundle.getSerializable(Helper.ARG_STATUS_DRAFT);
|
|
|
|
|
Snackbar snackbar = Snackbar.make(binding.getRoot(), errorMessage, 5000);
|
|
|
|
|
View snackbarView = snackbar.getView();
|
|
|
|
|
TextView textView = snackbarView.findViewById(com.google.android.material.R.id.snackbar_text);
|
|
|
|
|
textView.setMaxLines(5);
|
|
|
|
|
snackbar
|
|
|
|
|
.setAction(getString(R.string.open_draft), view -> {
|
|
|
|
|
Intent intentCompose = new Intent(context, ComposeActivity.class);
|
|
|
|
|
Bundle args2 = new Bundle();
|
|
|
|
|
args2.putSerializable(Helper.ARG_STATUS_DRAFT, statusDraft);
|
|
|
|
|
new CachedBundle(BaseMainActivity.this).insertBundle(args2, currentAccount, bundleId2 -> {
|
|
|
|
|
Bundle bundle2 = new Bundle();
|
|
|
|
|
bundle2.putLong(Helper.ARG_INTENT_ID, bundleId2);
|
|
|
|
|
intentCompose.putExtras(bundle2);
|
|
|
|
|
intentCompose.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
context.startActivity(intentCompose);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -246,94 +257,98 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|
|
|
|
private final BroadcastReceiver broadcast_data = new BroadcastReceiver() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
Bundle b = intent.getExtras();
|
|
|
|
|
if (b != null) {
|
|
|
|
|
if (b.getBoolean(Helper.RECEIVE_REDRAW_TOPBAR, false)) {
|
|
|
|
|
List<MastodonList> mastodonLists = (List<MastodonList>) b.getSerializable(Helper.RECEIVE_MASTODON_LIST);
|
|
|
|
|
redrawPinned(mastodonLists);
|
|
|
|
|
}
|
|
|
|
|
if (b.getBoolean(Helper.RECEIVE_REDRAW_BOTTOM, false)) {
|
|
|
|
|
bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView);
|
|
|
|
|
if (bottomMenu != null) {
|
|
|
|
|
//ManageClick on bottom menu items
|
|
|
|
|
if (binding.bottomNavView.findViewById(R.id.nav_home) != null) {
|
|
|
|
|
binding.bottomNavView.findViewById(R.id.nav_home).setOnLongClickListener(view -> {
|
|
|
|
|
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_home);
|
|
|
|
|
if (position >= 0) {
|
|
|
|
|
manageFilters(position);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (binding.bottomNavView.findViewById(R.id.nav_local) != null) {
|
|
|
|
|
binding.bottomNavView.findViewById(R.id.nav_local).setOnLongClickListener(view -> {
|
|
|
|
|
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_local);
|
|
|
|
|
Bundle args = intent.getExtras();
|
|
|
|
|
if (args != null) {
|
|
|
|
|
long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
|
|
|
|
|
new CachedBundle(BaseMainActivity.this).getBundle(bundleId, currentAccount, bundle -> {
|
|
|
|
|
if (bundle.getBoolean(Helper.RECEIVE_REDRAW_TOPBAR, false)) {
|
|
|
|
|
List<MastodonList> mastodonLists = (List<MastodonList>) bundle.getSerializable(Helper.RECEIVE_MASTODON_LIST);
|
|
|
|
|
redrawPinned(mastodonLists);
|
|
|
|
|
}
|
|
|
|
|
if (bundle.getBoolean(Helper.RECEIVE_REDRAW_BOTTOM, false)) {
|
|
|
|
|
bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView);
|
|
|
|
|
if (bottomMenu != null) {
|
|
|
|
|
//ManageClick on bottom menu items
|
|
|
|
|
if (binding.bottomNavView.findViewById(R.id.nav_home) != null) {
|
|
|
|
|
binding.bottomNavView.findViewById(R.id.nav_home).setOnLongClickListener(view -> {
|
|
|
|
|
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_home);
|
|
|
|
|
if (position >= 0) {
|
|
|
|
|
manageFilters(position);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (binding.bottomNavView.findViewById(R.id.nav_local) != null) {
|
|
|
|
|
binding.bottomNavView.findViewById(R.id.nav_local).setOnLongClickListener(view -> {
|
|
|
|
|
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_local);
|
|
|
|
|
if (position >= 0) {
|
|
|
|
|
manageFilters(position);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (binding.bottomNavView.findViewById(R.id.nav_public) != null) {
|
|
|
|
|
binding.bottomNavView.findViewById(R.id.nav_public).setOnLongClickListener(view -> {
|
|
|
|
|
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_public);
|
|
|
|
|
if (position >= 0) {
|
|
|
|
|
manageFilters(position);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
binding.bottomNavView.setOnItemSelectedListener(item -> {
|
|
|
|
|
int itemId = item.getItemId();
|
|
|
|
|
int position = BottomMenu.getPosition(bottomMenu, itemId);
|
|
|
|
|
if (position >= 0) {
|
|
|
|
|
manageFilters(position);
|
|
|
|
|
if (binding.viewPager.getCurrentItem() == position) {
|
|
|
|
|
scrollToTop();
|
|
|
|
|
} else {
|
|
|
|
|
binding.viewPager.setCurrentItem(position, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (binding.bottomNavView.findViewById(R.id.nav_public) != null) {
|
|
|
|
|
binding.bottomNavView.findViewById(R.id.nav_public).setOnLongClickListener(view -> {
|
|
|
|
|
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_public);
|
|
|
|
|
if (position >= 0) {
|
|
|
|
|
manageFilters(position);
|
|
|
|
|
} else if (bundle.getBoolean(Helper.RECEIVE_RECREATE_ACTIVITY, false)) {
|
|
|
|
|
recreate();
|
|
|
|
|
} else if (bundle.getBoolean(Helper.RECEIVE_NEW_MESSAGE, false)) {
|
|
|
|
|
Status statusSent = (Status) bundle.getSerializable(Helper.RECEIVE_STATUS_ACTION);
|
|
|
|
|
String statusEditId = bundle.getString(Helper.ARG_EDIT_STATUS_ID, null);
|
|
|
|
|
Snackbar.make(binding.displaySnackBar, getString(R.string.message_has_been_sent), Snackbar.LENGTH_LONG)
|
|
|
|
|
.setAction(getString(R.string.display), view -> {
|
|
|
|
|
Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class);
|
|
|
|
|
Bundle args2 = new Bundle();
|
|
|
|
|
args2.putSerializable(Helper.ARG_STATUS, statusSent);
|
|
|
|
|
new CachedBundle(BaseMainActivity.this).insertBundle(args2, currentAccount, bundleId2 -> {
|
|
|
|
|
Bundle bundle2 = new Bundle();
|
|
|
|
|
bundle.putLong(Helper.ARG_INTENT_ID, bundleId2);
|
|
|
|
|
intentContext.putExtras(bundle2);
|
|
|
|
|
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
startActivity(intentContext);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.show();
|
|
|
|
|
//The message was edited, we need to update the timeline
|
|
|
|
|
if (statusEditId != null) {
|
|
|
|
|
//Update message in cache
|
|
|
|
|
new Thread(() -> {
|
|
|
|
|
StatusCache statusCache = new StatusCache();
|
|
|
|
|
statusCache.instance = BaseMainActivity.currentInstance;
|
|
|
|
|
statusCache.user_id = BaseMainActivity.currentUserID;
|
|
|
|
|
statusCache.status = statusSent;
|
|
|
|
|
statusCache.status_id = statusEditId;
|
|
|
|
|
try {
|
|
|
|
|
new StatusCache(BaseMainActivity.this).updateIfExists(statusCache);
|
|
|
|
|
} catch (DBException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}).start();
|
|
|
|
|
//Update timelines
|
|
|
|
|
sendAction(context, Helper.ARG_STATUS_UPDATED, statusSent, null);
|
|
|
|
|
}
|
|
|
|
|
binding.bottomNavView.setOnItemSelectedListener(item -> {
|
|
|
|
|
int itemId = item.getItemId();
|
|
|
|
|
int position = BottomMenu.getPosition(bottomMenu, itemId);
|
|
|
|
|
if (position >= 0) {
|
|
|
|
|
if (binding.viewPager.getCurrentItem() == position) {
|
|
|
|
|
scrollToTop();
|
|
|
|
|
} else {
|
|
|
|
|
binding.viewPager.setCurrentItem(position, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (b.getBoolean(Helper.RECEIVE_RECREATE_ACTIVITY, false)) {
|
|
|
|
|
recreate();
|
|
|
|
|
} else if (b.getBoolean(Helper.RECEIVE_NEW_MESSAGE, false)) {
|
|
|
|
|
Status statusSent = (Status) b.getSerializable(Helper.RECEIVE_STATUS_ACTION);
|
|
|
|
|
String statusEditId = b.getString(Helper.ARG_EDIT_STATUS_ID, null);
|
|
|
|
|
Snackbar.make(binding.displaySnackBar, getString(R.string.message_has_been_sent), Snackbar.LENGTH_LONG)
|
|
|
|
|
.setAction(getString(R.string.display), view -> {
|
|
|
|
|
Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class);
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putSerializable(Helper.ARG_STATUS, statusSent);
|
|
|
|
|
new CachedBundle(BaseMainActivity.this).insertBundle(args, currentAccount, bundleId -> {
|
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
|
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
|
|
|
|
|
intentContext.putExtras(bundle);
|
|
|
|
|
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
startActivity(intentContext);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.show();
|
|
|
|
|
//The message was edited, we need to update the timeline
|
|
|
|
|
if (statusEditId != null) {
|
|
|
|
|
//Update message in cache
|
|
|
|
|
new Thread(() -> {
|
|
|
|
|
StatusCache statusCache = new StatusCache();
|
|
|
|
|
statusCache.instance = BaseMainActivity.currentInstance;
|
|
|
|
|
statusCache.user_id = BaseMainActivity.currentUserID;
|
|
|
|
|
statusCache.status = statusSent;
|
|
|
|
|
statusCache.status_id = statusEditId;
|
|
|
|
|
try {
|
|
|
|
|
new StatusCache(BaseMainActivity.this).updateIfExists(statusCache);
|
|
|
|
|
} catch (DBException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}).start();
|
|
|
|
|
//Update timelines
|
|
|
|
|
sendAction(context, Helper.ARG_STATUS_UPDATED, statusSent, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -707,12 +722,17 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|
|
|
|
}
|
|
|
|
|
viewPager.setCurrentItem(position);
|
|
|
|
|
}
|
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
|
b.putBoolean(ARG_REFRESH_NOTFICATION, true);
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putBoolean(ARG_REFRESH_NOTFICATION, true);
|
|
|
|
|
Intent intentBC = new Intent(Helper.RECEIVE_STATUS_ACTION);
|
|
|
|
|
intentBC.setPackage(BuildConfig.APPLICATION_ID);
|
|
|
|
|
intentBC.putExtras(b);
|
|
|
|
|
activity.sendBroadcast(intentBC);
|
|
|
|
|
new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> {
|
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
|
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
|
|
|
|
|
intentBC.putExtras(bundle);
|
|
|
|
|
activity.sendBroadcast(intentBC);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}, 1000);
|
|
|
|
|
intent.removeExtra(Helper.INTENT_ACTION);
|
|
|
|
|