1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-04 14:17:30 +00:00

Fix DM fragments, comment out deprecated activities

This commit is contained in:
Ammar Githam 2020-09-05 16:16:11 +09:00
parent 290ed50287
commit cc9348d8c5
22 changed files with 4258 additions and 4180 deletions

View File

@ -8,6 +8,7 @@ import androidx.core.app.NotificationManagerCompat;
import androidx.multidex.MultiDexApplication; import androidx.multidex.MultiDexApplication;
import com.facebook.drawee.backends.pipeline.Fresco; import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import java.net.CookieHandler; import java.net.CookieHandler;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -36,7 +37,12 @@ public final class InstaGrabberApplication extends MultiDexApplication {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
Fresco.initialize(this); final ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig
.newBuilder(this)
// .setMainDiskCacheConfig(diskCacheConfig)
.setDownsampleEnabled(true)
.build();
Fresco.initialize(this, imagePipelineConfig);
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
try { try {
@ -74,8 +80,8 @@ public final class InstaGrabberApplication extends MultiDexApplication {
if (datetimeParser == null) if (datetimeParser == null)
datetimeParser = new SimpleDateFormat( datetimeParser = new SimpleDateFormat(
settingsHelper.getBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED) ? settingsHelper.getBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED) ?
settingsHelper.getString(Constants.CUSTOM_DATE_TIME_FORMAT) : settingsHelper.getString(Constants.CUSTOM_DATE_TIME_FORMAT) :
settingsHelper.getString(Constants.DATE_TIME_FORMAT), LocaleUtils.getCurrentLocale()); settingsHelper.getString(Constants.DATE_TIME_FORMAT), LocaleUtils.getCurrentLocale());
settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString()); settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString());
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,94 +1,94 @@
package awais.instagrabber.activities; // package awais.instagrabber.activities;
//
import android.os.Bundle; // import android.os.Bundle;
import android.view.View; // import android.view.View;
import android.widget.TextView; // import android.widget.TextView;
//
import androidx.annotation.NonNull; // import androidx.annotation.NonNull;
import androidx.annotation.Nullable; // import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView; // import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.Toolbar; // import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; // import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.navigation.NavController; // import androidx.navigation.NavController;
import androidx.navigation.NavDestination; // import androidx.navigation.NavDestination;
import androidx.navigation.Navigation; // import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration; // import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI; // import androidx.navigation.ui.NavigationUI;
//
import awais.instagrabber.R; // import awais.instagrabber.R;
import awais.instagrabber.databinding.ActivityDirectMessagesBinding; // import awais.instagrabber.databinding.ActivityDirectMessagesBinding;
import awais.instagrabber.fragments.directmessages.DirectMessageThreadFragmentArgs; // import awais.instagrabber.fragments.directmessages.DirectMessageThreadFragmentArgs;
import awais.instagrabber.utils.Constants; // import awais.instagrabber.utils.Constants;
import static awais.instagrabber.utils.Utils.settingsHelper; // import static awais.instagrabber.utils.Utils.settingsHelper;
//
@Deprecated // @Deprecated
public class DirectMessagesActivity extends BaseLanguageActivity implements NavController.OnDestinationChangedListener { // public class DirectMessagesActivity extends BaseLanguageActivity implements NavController.OnDestinationChangedListener {
//
private TextView toolbarTitle; // private TextView toolbarTitle;
private AppCompatImageView dmInfo, dmSeen; // private AppCompatImageView dmInfo, dmSeen;
//
@Override // @Override
protected void onCreate(Bundle savedInstanceState) { // protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
final ActivityDirectMessagesBinding binding = ActivityDirectMessagesBinding.inflate(getLayoutInflater()); // final ActivityDirectMessagesBinding binding = ActivityDirectMessagesBinding.inflate(getLayoutInflater());
final CoordinatorLayout root = binding.getRoot(); // final CoordinatorLayout root = binding.getRoot();
setContentView(root); // setContentView(root);
//
toolbarTitle = binding.toolbarTitle; // toolbarTitle = binding.toolbarTitle;
//
final Toolbar toolbar = binding.toolbar; // final Toolbar toolbar = binding.toolbar;
setSupportActionBar(toolbar); // setSupportActionBar(toolbar);
//
dmInfo = binding.dmInfo; // dmInfo = binding.dmInfo;
dmSeen = binding.dmSeen; // dmSeen = binding.dmSeen;
//
final NavController navController = Navigation.findNavController(this, R.id.direct_messages_nav_host_fragment); // final NavController navController = Navigation.findNavController(this, R.id.direct_messages_nav_host_fragment);
navController.addOnDestinationChangedListener(this); // navController.addOnDestinationChangedListener(this);
final AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build(); // final AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build();
NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration); // NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration);
} // }
//
@Override // @Override
public void onDestinationChanged(@NonNull final NavController controller, // public void onDestinationChanged(@NonNull final NavController controller,
@NonNull final NavDestination destination, // @NonNull final NavDestination destination,
@Nullable final Bundle arguments) { // @Nullable final Bundle arguments) {
switch (destination.getId()) { // switch (destination.getId()) {
case R.id.directMessagesInboxFragment: // case R.id.directMessagesInboxFragment:
setToolbarTitle(R.string.action_dms); // setToolbarTitle(R.string.action_dms);
dmInfo.setVisibility(View.GONE); // dmInfo.setVisibility(View.GONE);
dmSeen.setVisibility(View.GONE); // dmSeen.setVisibility(View.GONE);
return; // return;
case R.id.directMessagesThreadFragment: // case R.id.directMessagesThreadFragment:
if (arguments == null) { // if (arguments == null) {
return; // return;
} // }
final String title = DirectMessageThreadFragmentArgs.fromBundle(arguments).getTitle(); // final String title = DirectMessageThreadFragmentArgs.fromBundle(arguments).getTitle();
setToolbarTitle(title); // setToolbarTitle(title);
dmInfo.setVisibility(View.VISIBLE); // dmInfo.setVisibility(View.VISIBLE);
dmSeen.setVisibility(settingsHelper.getBoolean(Constants.DM_MARK_AS_SEEN) ? View.GONE : View.VISIBLE); // dmSeen.setVisibility(settingsHelper.getBoolean(Constants.DM_MARK_AS_SEEN) ? View.GONE : View.VISIBLE);
return; // return;
case R.id.directMessagesSettingsFragment: // case R.id.directMessagesSettingsFragment:
if (arguments == null) { // if (arguments == null) {
return; // return;
} // }
setToolbarTitle(R.string.action_settings); // setToolbarTitle(R.string.action_settings);
dmInfo.setVisibility(View.GONE); // dmInfo.setVisibility(View.GONE);
dmSeen.setVisibility(View.GONE); // dmSeen.setVisibility(View.GONE);
return; // return;
} // }
} // }
//
private void setToolbarTitle(final String text) { // private void setToolbarTitle(final String text) {
if (toolbarTitle == null) { // if (toolbarTitle == null) {
return; // return;
} // }
toolbarTitle.setText(text); // toolbarTitle.setText(text);
} // }
//
private void setToolbarTitle(final int resourceId) { // private void setToolbarTitle(final int resourceId) {
if (toolbarTitle == null) { // if (toolbarTitle == null) {
return; // return;
} // }
toolbarTitle.setText(resourceId); // toolbarTitle.setText(resourceId);
} // }
} // }

View File

@ -50,7 +50,8 @@ public class MainActivity extends BaseLanguageActivity {
R.id.locationFragment, R.id.locationFragment,
R.id.savedViewerFragment, R.id.savedViewerFragment,
R.id.commentsViewerFragment, R.id.commentsViewerFragment,
R.id.followViewerFragment); R.id.followViewerFragment,
R.id.directMessagesSettingsFragment);
private static final List<Integer> REMOVE_COLLAPSING_TOOLBAR_SCROLL_DESTINATIONS = Collections.singletonList(R.id.commentsViewerFragment); private static final List<Integer> REMOVE_COLLAPSING_TOOLBAR_SCROLL_DESTINATIONS = Collections.singletonList(R.id.commentsViewerFragment);
private ActivityMainBinding binding; private ActivityMainBinding binding;
private LiveData<NavController> currentNavControllerLiveData; private LiveData<NavController> currentNavControllerLiveData;

View File

@ -76,9 +76,10 @@ public final class NotificationsViewer extends BaseLanguageActivity implements S
final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> { final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> {
if (which == 0) if (which == 0)
searchUsername(notificationModel.getUsername()); searchUsername(notificationModel.getUsername());
else if (which == 1 && commentDialogList.length == 2) else if (which == 1 && commentDialogList.length == 2) {
startActivity(new Intent(getApplicationContext(), PostViewer.class) // startActivity(new Intent(getApplicationContext(), PostViewer.class)
.putExtra(Constants.EXTRAS_POST, new PostModel(notificationModel.getShortcode(), false))); // .putExtra(Constants.EXTRAS_POST, new PostModel(notificationModel.getShortcode(), false)));
}
else if (which == 1) new ProfileAction().execute("/approve/"); else if (which == 1) new ProfileAction().execute("/approve/");
else if (which == 2) new ProfileAction().execute("/ignore/"); else if (which == 2) new ProfileAction().execute("/ignore/");
}; };
@ -123,7 +124,7 @@ public final class NotificationsViewer extends BaseLanguageActivity implements S
private void searchUsername(final String text) { private void searchUsername(final String text) {
startActivity(new Intent(getApplicationContext(), ProfileViewer.class).putExtra(Constants.EXTRAS_USERNAME, text)); // startActivity(new Intent(getApplicationContext(), ProfileViewer.class).putExtra(Constants.EXTRAS_USERNAME, text));
} }
class ProfileAction extends AsyncTask<String, Void, Void> { class ProfileAction extends AsyncTask<String, Void, Void> {

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
package awais.instagrabber.adapters.viewholder; package awais.instagrabber.adapters.viewholder;
import android.content.Context; import android.content.Context;
import android.net.Uri;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -8,7 +9,11 @@ import androidx.annotation.NonNull;
import androidx.core.text.HtmlCompat; import androidx.core.text.HtmlCompat;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.view.SimpleDraweeView; import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.imagepipeline.common.ResizeOptions;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.databinding.LayoutDmInboxItemBinding; import awais.instagrabber.databinding.LayoutDmInboxItemBinding;
@ -50,14 +55,27 @@ public final class DirectMessageInboxItemViewHolder extends RecyclerView.ViewHol
multipleProfilePics[i].setImageURI(users[i].getSdProfilePic()); multipleProfilePics[i].setImageURI(users[i].getSdProfilePic());
} }
} else { } else {
binding.ivProfilePic.setVisibility(View.VISIBLE); final String uriString = users.length == 1 ? users[0].getSdProfilePic() : null;
multipleProfilePicsContainer.setVisibility(View.GONE); if (uriString == null) {
binding.ivProfilePic.setImageURI(users.length == 1 ? users[0].getSdProfilePic() : null); binding.ivProfilePic.setVisibility(View.GONE);
} else {
binding.ivProfilePic.setVisibility(View.VISIBLE);
multipleProfilePicsContainer.setVisibility(View.GONE);
final ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uriString))
.setResizeOptions(new ResizeOptions(50, 50))
.build();
binding.ivProfilePic.setController(
Fresco.newDraweeControllerBuilder()
.setOldController(binding.ivProfilePic.getController())
.setImageRequest(request)
.build()
);
}
} }
binding.tvUsername.setText(model.getThreadTitle()); binding.tvUsername.setText(model.getThreadTitle());
final DirectItemModel lastItemModel = itemModels[itemModels.length - 1]; final DirectItemModel lastItemModel = itemModels[itemModels.length - 1];
final DirectItemType itemType = lastItemModel.getItemType(); final DirectItemType itemType = lastItemModel.getItemType();
binding.notTextType.setVisibility(itemType != DirectItemType.TEXT ? View.VISIBLE : View.GONE); // binding.notTextType.setVisibility(itemType != DirectItemType.TEXT ? View.VISIBLE : View.GONE);
final Context context = itemView.getContext(); final Context context = itemView.getContext();
final CharSequence messageText; final CharSequence messageText;
switch (itemType) { switch (itemType) {

View File

@ -21,8 +21,6 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import java.util.ArrayList; import java.util.ArrayList;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.activities.MainActivity;
import awais.instagrabber.activities.MainActivityBackup;
import awais.instagrabber.adapters.SimpleAdapter; import awais.instagrabber.adapters.SimpleAdapter;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.DataBox; import awais.instagrabber.utils.DataBox;
@ -113,10 +111,10 @@ public final class QuickAccessDialog extends BottomSheetDialogFragment implement
else Utils.showImportExportDialog(v.getContext()); else Utils.showImportExportDialog(v.getContext());
} else if (tag instanceof DataBox.FavoriteModel) { } else if (tag instanceof DataBox.FavoriteModel) {
if (MainActivityBackup.scanHack != null) { // if (MainActivityBackup.scanHack != null) {
MainActivityBackup.scanHack.onResult(((DataBox.FavoriteModel) tag).getQuery()); // MainActivityBackup.scanHack.onResult(((DataBox.FavoriteModel) tag).getQuery());
dismiss(); // dismiss();
} // }
} else if (tag instanceof DataBox.CookieModel) { } else if (tag instanceof DataBox.CookieModel) {
final DataBox.CookieModel cookieModel = (DataBox.CookieModel) tag; final DataBox.CookieModel cookieModel = (DataBox.CookieModel) tag;
@ -140,8 +138,8 @@ public final class QuickAccessDialog extends BottomSheetDialogFragment implement
Utils.dataBox.delFavorite(favoriteModel); Utils.dataBox.delFavorite(favoriteModel);
favoritesAdapter.setItems(Utils.dataBox.getAllFavorites()); favoritesAdapter.setItems(Utils.dataBox.getAllFavorites());
}) })
.setNegativeButton(R.string.no, null).setMessage(getString(R.string.quick_access_confirm_delete, .setNegativeButton(R.string.no, null).setMessage(getString(R.string.quick_access_confirm_delete,
favoriteModel.getQuery())).show(); favoriteModel.getQuery())).show();
} else if (tag instanceof DataBox.CookieModel) { } else if (tag instanceof DataBox.CookieModel) {
final DataBox.CookieModel cookieModel = (DataBox.CookieModel) tag; final DataBox.CookieModel cookieModel = (DataBox.CookieModel) tag;
@ -153,8 +151,8 @@ public final class QuickAccessDialog extends BottomSheetDialogFragment implement
Utils.dataBox.delUserCookie(cookieModel); Utils.dataBox.delUserCookie(cookieModel);
rvQuickAccess.findViewWithTag(cookieModel).setVisibility(View.GONE); rvQuickAccess.findViewWithTag(cookieModel).setVisibility(View.GONE);
}) })
.setNegativeButton(R.string.no, null).setMessage(getString(R.string.quick_access_confirm_delete, .setNegativeButton(R.string.no, null).setMessage(getString(R.string.quick_access_confirm_delete,
cookieModel.getUsername())).show(); cookieModel.getUsername())).show();
} }
return true; return true;

View File

@ -187,11 +187,6 @@ public class HashTagFragment extends Fragment {
return; return;
} }
if (checkAndResetAction()) return; if (checkAndResetAction()) return;
// startActivity(new Intent(requireContext(), PostViewer.class)
// .putExtra(Constants.EXTRAS_INDEX, position)
// .putExtra(Constants.EXTRAS_POST, postModel)
// .putExtra(Constants.EXTRAS_USER, hashtag)
// .putExtra(Constants.EXTRAS_TYPE, PostItemType.MAIN));
final List<PostModel> postModels = postsViewModel.getList().getValue(); final List<PostModel> postModels = postsViewModel.getList().getValue();
if (postModels == null || postModels.size() == 0) return; if (postModels == null || postModels.size() == 0) return;
if (postModels.get(0) == null) return; if (postModels.get(0) == null) return;

View File

@ -209,12 +209,6 @@ public class LocationFragment extends Fragment {
idsOrShortCodes, idsOrShortCodes,
isId); isId);
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);
// startActivity(new Intent(requireContext(), PostViewer.class)
// .putExtra(Constants.EXTRAS_INDEX, position)
// .putExtra(Constants.EXTRAS_POST, postModel)
// .putExtra(Constants.EXTRAS_USER, locationId)
// .putExtra(Constants.EXTRAS_TYPE, PostItemType.MAIN));
}, (model, position) -> { }, (model, position) -> {
if (!postsAdapter.isSelecting()) { if (!postsAdapter.isSelecting()) {
checkAndResetAction(); checkAndResetAction();

View File

@ -355,8 +355,6 @@ public class StoryViewerFragment extends Fragment {
idsOrShortCodes, idsOrShortCodes,
isId); isId);
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);
// startActivity(new Intent(requireContext(), PostViewer.class)
// .putExtra(Constants.EXTRAS_POST, new PostModel(, ));
}); });
final View.OnClickListener storyActionListener = v -> { final View.OnClickListener storyActionListener = v -> {
final Object tag = v.getTag(); final Object tag = v.getTag();

View File

@ -1,6 +1,6 @@
package awais.instagrabber.fragments.directmessages; package awais.instagrabber.fragments.directmessages;
import android.content.Intent; import android.content.DialogInterface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
@ -35,7 +35,6 @@ import java.util.List;
import awais.instagrabber.BuildConfig; import awais.instagrabber.BuildConfig;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.activities.ProfileViewer;
import awais.instagrabber.adapters.DirectMessageMembersAdapter; import awais.instagrabber.adapters.DirectMessageMembersAdapter;
import awais.instagrabber.asyncs.direct_messages.DirectMessageInboxThreadFetcher; import awais.instagrabber.asyncs.direct_messages.DirectMessageInboxThreadFetcher;
import awais.instagrabber.databinding.FragmentDirectMessagesSettingsBinding; import awais.instagrabber.databinding.FragmentDirectMessagesSettingsBinding;
@ -46,20 +45,23 @@ import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
public class DirectMessageSettingsFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { public class DirectMessageSettingsFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = "DirectMessagesSettingsFrag"; private static final String TAG = "DirectMsgsSettingsFrag";
private FragmentActivity fragmentActivity; private FragmentActivity fragmentActivity;
private RecyclerView userList, leftUserList; private RecyclerView userList;
private RecyclerView leftUserList;
private EditText titleText; private EditText titleText;
private View leftTitle; private View leftTitle;
private AppCompatImageView titleSend; private AppCompatImageView titleSend;
private AppCompatButton btnLeave; private AppCompatButton btnLeave;
private LinearLayoutManager layoutManager, layoutManagerDos; private LinearLayoutManager layoutManager;
private LinearLayoutManager layoutManagerDos;
private String threadId, threadTitle; private String threadId, threadTitle;
private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE); private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE);
private boolean amAdmin; private boolean amAdmin;
private AsyncTask<Void, Void, InboxThreadModel> currentlyRunning; private AsyncTask<Void, Void, InboxThreadModel> currentlyRunning;
private DirectMessageMembersAdapter memberAdapter, leftAdapter; private DirectMessageMembersAdapter memberAdapter;
private DirectMessageMembersAdapter leftAdapter;
private View.OnClickListener clickListener, basicClickListener; private View.OnClickListener clickListener, basicClickListener;
private final FetchListener<InboxThreadModel> fetchListener = new FetchListener<InboxThreadModel>() { private final FetchListener<InboxThreadModel> fetchListener = new FetchListener<InboxThreadModel>() {
@ -69,8 +71,13 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr
@Override @Override
public void onResult(final InboxThreadModel threadModel) { public void onResult(final InboxThreadModel threadModel) {
final List<Long> adminList = Arrays.asList(threadModel.getAdmins()); final List<Long> adminList = Arrays.asList(threadModel.getAdmins());
amAdmin = adminList.contains(Long.parseLong(Utils.getUserIdFromCookie(cookie))); final String userIdFromCookie = Utils.getUserIdFromCookie(cookie);
memberAdapter = new DirectMessageMembersAdapter(threadModel.getUsers(), adminList, requireContext(), amAdmin ? clickListener : basicClickListener); if (userIdFromCookie == null) return;
amAdmin = adminList.contains(Long.parseLong(userIdFromCookie));
memberAdapter = new DirectMessageMembersAdapter(threadModel.getUsers(),
adminList,
requireContext(),
amAdmin ? clickListener : basicClickListener);
userList.setAdapter(memberAdapter); userList.setAdapter(memberAdapter);
if (threadModel.getLeftUsers() != null && threadModel.getLeftUsers().length > 0) { if (threadModel.getLeftUsers() != null && threadModel.getLeftUsers().length > 0) {
leftTitle.setVisibility(View.VISIBLE); leftTitle.setVisibility(View.VISIBLE);
@ -84,15 +91,12 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr
public void onCreate(@Nullable final Bundle savedInstanceState) { public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
fragmentActivity = requireActivity(); fragmentActivity = requireActivity();
basicClickListener = v -> { basicClickListener = v -> {
final Object tag = v.getTag(); final Object tag = v.getTag();
if (tag instanceof ProfileModel) { if (tag instanceof ProfileModel) {
ProfileModel model = (ProfileModel) tag; ProfileModel model = (ProfileModel) tag;
startActivity( // startActivity(new Intent(requireContext(), ProfileViewer.class)
new Intent(requireContext(), ProfileViewer.class) // .putExtra(Constants.EXTRAS_USERNAME, model.getUsername()));
.putExtra(Constants.EXTRAS_USERNAME, model.getUsername())
);
} }
}; };
@ -101,28 +105,25 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr
if (tag instanceof ProfileModel) { if (tag instanceof ProfileModel) {
ProfileModel model = (ProfileModel) tag; ProfileModel model = (ProfileModel) tag;
if (!amAdmin || model.getId().equals(Utils.getUserIdFromCookie(cookie))) { if (!amAdmin || model.getId().equals(Utils.getUserIdFromCookie(cookie))) {
startActivity( // startActivity(new Intent(requireContext(), ProfileViewer.class)
new Intent(requireContext(), ProfileViewer.class) // .putExtra(Constants.EXTRAS_USERNAME, model.getUsername()));
.putExtra(Constants.EXTRAS_USERNAME, model.getUsername()) } else {
); final ArrayAdapter<String> adapter = new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, new String[]{
} getString(R.string.open_profile),
else { getString(R.string.dms_action_kick),
new AlertDialog.Builder(requireContext()).setAdapter( });
new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, new String[]{ final DialogInterface.OnClickListener clickListener = (d, w) -> {
getString(R.string.open_profile), if (w == 0) {
getString(R.string.dms_action_kick), // startActivity(new Intent(requireContext(), ProfileViewer.class)
}), // .putExtra(Constants.EXTRAS_USERNAME, model.getUsername()));
(d,w) -> { } else if (w == 1) {
if (w == 0) new ChangeSettings().execute("remove_users", model.getId());
startActivity( onRefresh();
new Intent(requireContext(), ProfileViewer.class) }
.putExtra(Constants.EXTRAS_USERNAME, model.getUsername()) };
); new AlertDialog.Builder(requireContext())
else if (w == 1) { .setAdapter(adapter, clickListener)
new ChangeSettings().execute("remove_users", model.getId()); .show();
onRefresh();
}
}).show();
} }
} }
}; };
@ -146,7 +147,9 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr
return false; return false;
} }
}; };
if (getArguments() == null) {
return null;
}
threadId = DirectMessageSettingsFragmentArgs.fromBundle(getArguments()).getThreadId(); threadId = DirectMessageSettingsFragmentArgs.fromBundle(getArguments()).getThreadId();
threadTitle = DirectMessageSettingsFragmentArgs.fromBundle(getArguments()).getTitle(); threadTitle = DirectMessageSettingsFragmentArgs.fromBundle(getArguments()).getTitle();
binding.swipeRefreshLayout.setEnabled(false); binding.swipeRefreshLayout.setEnabled(false);
@ -185,11 +188,9 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr
btnLeave = binding.btnLeave; btnLeave = binding.btnLeave;
btnLeave.setOnClickListener(v -> { btnLeave.setOnClickListener(v -> {
new AlertDialog.Builder(requireContext()).setTitle(R.string.dms_action_leave_question) new AlertDialog.Builder(requireContext()).setTitle(R.string.dms_action_leave_question)
.setPositiveButton(R.string.yes, (x,y) -> { .setPositiveButton(R.string.yes, (x, y) -> new ChangeSettings().execute("leave"))
new ChangeSettings().execute("leave"); .setNegativeButton(R.string.no, null)
}) .show();
.setNegativeButton(R.string.no, null)
.show();
}); });
currentlyRunning = new DirectMessageInboxThreadFetcher(threadId, null, null, fetchListener).execute(); currentlyRunning = new DirectMessageInboxThreadFetcher(threadId, null, null, fetchListener).execute();
@ -207,7 +208,9 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr
try { try {
currentlyRunning.cancel(true); currentlyRunning.cancel(true);
} catch (final Exception e) { } catch (final Exception e) {
if (BuildConfig.DEBUG) Log.e(TAG, "", e); if (BuildConfig.DEBUG) {
Log.e(TAG, "", e);
}
} }
} }
} }
@ -219,14 +222,14 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr
protected Void doInBackground(String... rawAction) { protected Void doInBackground(String... rawAction) {
action = rawAction[0]; action = rawAction[0];
if (rawAction.length == 2) argument = rawAction[1]; if (rawAction.length == 2) argument = rawAction[1];
final String url = "https://i.instagram.com/api/v1/direct_v2/threads/"+threadId+"/"+action+"/"; final String url = "https://i.instagram.com/api/v1/direct_v2/threads/" + threadId + "/" + action + "/";
try { try {
String urlParameters = "_csrftoken=" + cookie.split("csrftoken=")[1].split(";")[0] String urlParameters = "_csrftoken=" + cookie.split("csrftoken=")[1].split(";")[0]
+"&_uuid=" + Utils.settingsHelper.getString(Constants.DEVICE_UUID); + "&_uuid=" + Utils.settingsHelper.getString(Constants.DEVICE_UUID);
if (action.equals("update_title")) if (action.equals("update_title"))
urlParameters += "&title=" + URLEncoder.encode(titleText.getText().toString(), "UTF-8") urlParameters += "&title=" + URLEncoder.encode(titleText.getText().toString(), "UTF-8")
.replaceAll("\\+", "%20").replaceAll("%21", "!").replaceAll("%27", "'") .replaceAll("\\+", "%20").replaceAll("%21", "!").replaceAll("%27", "'")
.replaceAll("%28", "(").replaceAll("%29", ")").replaceAll("%7E", "~"); .replaceAll("%28", "(").replaceAll("%29", ")").replaceAll("%7E", "~");
else if (action.startsWith("remove_users")) else if (action.startsWith("remove_users"))
urlParameters += ("&user_ids=[" + argument + "]"); urlParameters += ("&user_ids=[" + argument + "]");
final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection();
@ -260,16 +263,13 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr
titleSend.setVisibility(View.GONE); titleSend.setVisibility(View.GONE);
titleText.clearFocus(); titleText.clearFocus();
DirectMessageThreadFragment.hasSentSomething = true; DirectMessageThreadFragment.hasSentSomething = true;
} } else if (action.equals("leave")) {
else if (action.equals("leave")) {
DirectMessageInboxFragment.refreshPlease = true; DirectMessageInboxFragment.refreshPlease = true;
NavHostFragment.findNavController(DirectMessageSettingsFragment.this).popBackStack(R.id.directMessagesInboxFragment, false); NavHostFragment.findNavController(DirectMessageSettingsFragment.this).popBackStack(R.id.directMessagesInboxFragment, false);
} } else {
else {
DirectMessageThreadFragment.hasSentSomething = true; DirectMessageThreadFragment.hasSentSomething = true;
} }
} } else Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
else Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
} }
} }
} }

View File

@ -12,6 +12,7 @@ import android.os.Handler;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -25,7 +26,6 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentContainerView;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
@ -50,7 +50,6 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.activities.PostViewer;
import awais.instagrabber.adapters.DirectMessageItemsAdapter; import awais.instagrabber.adapters.DirectMessageItemsAdapter;
import awais.instagrabber.asyncs.ImageUploader; import awais.instagrabber.asyncs.ImageUploader;
import awais.instagrabber.asyncs.direct_messages.DirectMessageInboxThreadFetcher; import awais.instagrabber.asyncs.direct_messages.DirectMessageInboxThreadFetcher;
@ -60,7 +59,6 @@ import awais.instagrabber.databinding.FragmentDirectMessagesThreadBinding;
import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.interfaces.MentionClickListener; import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ImageUploadOptions; import awais.instagrabber.models.ImageUploadOptions;
import awais.instagrabber.models.PostModel;
import awais.instagrabber.models.ProfileModel; import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.direct_messages.DirectItemModel; import awais.instagrabber.models.direct_messages.DirectItemModel;
import awais.instagrabber.models.direct_messages.InboxThreadModel; import awais.instagrabber.models.direct_messages.InboxThreadModel;
@ -76,14 +74,16 @@ public class DirectMessageThreadFragment extends Fragment {
private static final int PICK_IMAGE = 100; private static final int PICK_IMAGE = 100;
private AppCompatActivity fragmentActivity; private AppCompatActivity fragmentActivity;
private String threadId, threadTitle, cursor, lastMessage; private String threadId;
private String threadTitle;
private String cursor;
private String lastMessage;
private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE); private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE);
private final String myId = Utils.getUserIdFromCookie(cookie); private final String myId = Utils.getUserIdFromCookie(cookie);
private FragmentDirectMessagesThreadBinding binding; private FragmentDirectMessagesThreadBinding binding;
private DirectItemModelListViewModel listViewModel; private DirectItemModelListViewModel listViewModel;
private DirectItemModel directItemModel; private DirectItemModel directItemModel;
private RecyclerView messageList; private RecyclerView messageList;
// private AppCompatImageView dmInfo, dmSeen;
private boolean hasDeletedSomething; private boolean hasDeletedSomething;
private boolean hasOlder = true; private boolean hasOlder = true;
public static boolean hasSentSomething; public static boolean hasSentSomething;
@ -158,6 +158,8 @@ public class DirectMessageThreadFragment extends Fragment {
binding.swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
} }
}; };
private LinearLayout root;
private boolean shouldRefresh = true;
@Override @Override
public void onCreate(@Nullable final Bundle savedInstanceState) { public void onCreate(@Nullable final Bundle savedInstanceState) {
@ -166,27 +168,29 @@ public class DirectMessageThreadFragment extends Fragment {
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@Override
public void onResume() {
super.onResume();
if (hasSentSomething) {
new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@Override @Override
public View onCreateView(@NonNull final LayoutInflater inflater, public View onCreateView(@NonNull final LayoutInflater inflater,
final ViewGroup container, final ViewGroup container,
final Bundle savedInstanceState) { final Bundle savedInstanceState) {
binding = FragmentDirectMessagesThreadBinding.inflate(inflater, container, false); if (root != null) {
final FragmentContainerView containerTwo = (FragmentContainerView) container.getParent(); shouldRefresh = false;
// dmInfo = containerTwo.findViewById(R.id.dmInfo);
// dmSeen = containerTwo.findViewById(R.id.dmSeen);
final LinearLayout root = binding.getRoot();
listViewModel = new ViewModelProvider(fragmentActivity).get(DirectItemModelListViewModel.class);
if (getArguments() == null) {
return root; return root;
} }
binding = FragmentDirectMessagesThreadBinding.inflate(inflater, container, false);
root = binding.getRoot();
return root;
}
@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
if (!shouldRefresh) return;
init();
shouldRefresh = false;
}
private void init() {
listViewModel = new ViewModelProvider(fragmentActivity).get(DirectItemModelListViewModel.class);
if (getArguments() == null) return;
if (!DirectMessageThreadFragmentArgs.fromBundle(getArguments()).getThreadId().equals(threadId)) { if (!DirectMessageThreadFragmentArgs.fromBundle(getArguments()).getThreadId().equals(threadId)) {
listViewModel.empty(); listViewModel.empty();
threadId = DirectMessageThreadFragmentArgs.fromBundle(getArguments()).getThreadId(); threadId = DirectMessageThreadFragmentArgs.fromBundle(getArguments()).getThreadId();
@ -203,25 +207,14 @@ public class DirectMessageThreadFragment extends Fragment {
binding.image.setOnClickListener(clickListener); binding.image.setOnClickListener(clickListener);
final LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext()); final LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext());
layoutManager.setReverseLayout(true); layoutManager.setReverseLayout(true);
// layoutManager.setStackFromEnd(true);
messageList.setLayoutManager(layoutManager); messageList.setLayoutManager(layoutManager);
messageList.addOnScrollListener(new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { messageList.addOnScrollListener(new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> {
if (Utils.isEmpty(cursor) || !hasOlder) { if (Utils.isEmpty(cursor) || !hasOlder) {
return; return;
} }
new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, cursor, fetchListener).execute(); // serial because we don't want messages to be randomly ordered new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, cursor, fetchListener)
.execute(); // serial because we don't want messages to be randomly ordered
})); }));
// dmInfo.setOnClickListener(v -> {
// final NavDirections action =
// DirectMessageThreadFragmentDirections.actionDMThreadFragmentToDMSettingsFragment(threadId, threadTitle);
// NavHostFragment.findNavController(DirectMessageThreadFragment.this).navigate(action);
// });
// dmSeen.setOnClickListener(v -> {
// new ThreadAction().execute("seen", lastMessage);
// dmSeen.setVisibility(View.GONE);
// });
final DialogInterface.OnClickListener onDialogListener = (dialogInterface, which) -> { final DialogInterface.OnClickListener onDialogListener = (dialogInterface, which) -> {
if (which == 0) { if (which == 0) {
final DirectItemType itemType = directItemModel.getItemType(); final DirectItemType itemType = directItemModel.getItemType();
@ -248,11 +241,12 @@ public class DirectMessageThreadFragment extends Fragment {
final ProfileModel user = getUser(directItemModel.getUserId()); final ProfileModel user = getUser(directItemModel.getUserId());
final DirectItemModel.DirectItemMediaModel selectedItem = final DirectItemModel.DirectItemMediaModel selectedItem =
itemType == DirectItemType.MEDIA ? directItemModel.getMediaModel() : directItemModel.getRavenMediaModel().getMedia(); itemType == DirectItemType.MEDIA ? directItemModel.getMediaModel() : directItemModel.getRavenMediaModel().getMedia();
final String url = selectedItem.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO ? selectedItem.getVideoUrl() : selectedItem.getThumbUrl(); final String url = selectedItem.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO
? selectedItem.getVideoUrl()
: selectedItem.getThumbUrl();
if (url == null) { if (url == null) {
Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
} } else {
else {
Utils.dmDownload(requireContext(), user.getUsername(), DownloadMethod.DOWNLOAD_DIRECT, selectedItem); Utils.dmDownload(requireContext(), user.getUsername(), DownloadMethod.DOWNLOAD_DIRECT, selectedItem);
Toast.makeText(requireContext(), R.string.downloader_downloading_media, Toast.LENGTH_SHORT).show(); Toast.makeText(requireContext(), R.string.downloader_downloading_media, Toast.LENGTH_SHORT).show();
} }
@ -283,7 +277,7 @@ public class DirectMessageThreadFragment extends Fragment {
searchUsername(directItemModel.getText().toString().split("@")[1].split(" ")[0]); searchUsername(directItemModel.getText().toString().split("@")[1].split(" ")[0]);
break; break;
default: default:
Log.d("austin_debug", "unsupported type " + itemType); Log.d(TAG, "unsupported type " + itemType);
} }
} else if (which == 1) { } else if (which == 1) {
sendText(null, directItemModel.getItemId(), directItemModel.isLiked()); sendText(null, directItemModel.getItemId(), directItemModel.isLiked());
@ -350,9 +344,22 @@ public class DirectMessageThreadFragment extends Fragment {
messageList.setAdapter(adapter); messageList.setAdapter(adapter);
listViewModel.getList().observe(fragmentActivity, adapter::submitList); listViewModel.getList().observe(fragmentActivity, adapter::submitList);
if (listViewModel.isEmpty()) { if (listViewModel.isEmpty()) {
new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@Override
public void onResume() {
super.onResume();
if (hasSentSomething) {
new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(threadTitle);
} }
return root;
} }
@Override @Override
@ -361,6 +368,27 @@ public class DirectMessageThreadFragment extends Fragment {
item.setVisible(false); item.setVisible(false);
} }
@Override
public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) {
inflater.inflate(R.menu.dm_thread_menu, menu);
}
@Override
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
final int itemId = item.getItemId();
switch (itemId) {
case R.id.info:
final NavDirections action = DirectMessageThreadFragmentDirections.actionDMThreadFragmentToDMSettingsFragment(threadId, threadTitle);
NavHostFragment.findNavController(this).navigate(action);
return true;
case R.id.mark_as_seen:
new ThreadAction().execute("seen", lastMessage);
item.setVisible(false);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override @Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
@ -409,7 +437,8 @@ public class DirectMessageThreadFragment extends Fragment {
} }
DirectMessageInboxFragment.refreshPlease = true; DirectMessageInboxFragment.refreshPlease = true;
hasSentSomething = true; hasSentSomething = true;
new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}); });
} }
@ -433,7 +462,9 @@ public class DirectMessageThreadFragment extends Fragment {
// Broadcast // Broadcast
final DirectThreadBroadcaster.ImageBroadcastOptions options = new DirectThreadBroadcaster.ImageBroadcastOptions(true, uploadId); final DirectThreadBroadcaster.ImageBroadcastOptions options = new DirectThreadBroadcaster.ImageBroadcastOptions(true, uploadId);
hasSentSomething = true; hasSentSomething = true;
broadcast(options, broadcastResponse -> new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)); broadcast(options,
broadcastResponse -> new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR));
} catch (JSONException e) { } catch (JSONException e) {
Log.e(TAG, "Error parsing json response", e); Log.e(TAG, "Error parsing json response", e);
} }
@ -446,7 +477,8 @@ public class DirectMessageThreadFragment extends Fragment {
} }
} }
private void broadcast(final DirectThreadBroadcaster.BroadcastOptions broadcastOptions, final DirectThreadBroadcaster.OnBroadcastCompleteListener listener) { private void broadcast(final DirectThreadBroadcaster.BroadcastOptions broadcastOptions,
final DirectThreadBroadcaster.OnBroadcastCompleteListener listener) {
final DirectThreadBroadcaster broadcaster = new DirectThreadBroadcaster(threadId); final DirectThreadBroadcaster broadcaster = new DirectThreadBroadcaster(threadId);
broadcaster.setOnTaskCompleteListener(listener); broadcaster.setOnTaskCompleteListener(listener);
broadcaster.execute(broadcastOptions); broadcaster.execute(broadcastOptions);
@ -529,7 +561,8 @@ public class DirectMessageThreadFragment extends Fragment {
protected void onPostExecute(Void result) { protected void onPostExecute(Void result) {
if (hasDeletedSomething) { if (hasDeletedSomething) {
directItemModel = null; directItemModel = null;
new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
} }
} }

View File

@ -202,10 +202,6 @@ public class DiscoverFragment extends Fragment {
return; return;
} }
if (checkAndResetAction()) return; if (checkAndResetAction()) return;
// startActivity(new Intent(requireContext(), PostViewer.class)
// .putExtra(Constants.EXTRAS_INDEX, position)
// .putExtra(Constants.EXTRAS_TYPE, PostItemType.DISCOVER)
// .putExtra(Constants.EXTRAS_POST, new PostModel(model.getShortCode(), false)));
final List<DiscoverItemModel> discoverItemModels = discoverItemViewModel.getList().getValue(); final List<DiscoverItemModel> discoverItemModels = discoverItemViewModel.getList().getValue();
if (discoverItemModels == null || discoverItemModels.size() == 0) return; if (discoverItemModels == null || discoverItemModels.size() == 0) return;
if (discoverItemModels.get(0) == null) return; if (discoverItemModels.get(0) == null) return;

View File

@ -12,6 +12,8 @@ import android.text.style.StyleSpan;
import android.util.Log; import android.util.Log;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -179,12 +181,14 @@ public class ProfileFragment extends Fragment {
action.setUsername("@" + text); action.setUsername("@" + text);
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);
}; };
private MenuItem favMenuItem;
@Override @Override
public void onCreate(@Nullable final Bundle savedInstanceState) { public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
fragmentActivity = (MainActivity) requireActivity(); fragmentActivity = (MainActivity) requireActivity();
friendshipService = FriendshipService.getInstance(); friendshipService = FriendshipService.getInstance();
setHasOptionsMenu(true);
} }
@Override @Override
@ -225,6 +229,12 @@ public class ProfileFragment extends Fragment {
shouldRefresh = false; shouldRefresh = false;
} }
@Override
public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) {
inflater.inflate(R.menu.profile_menu, menu);
favMenuItem = menu.findItem(R.id.favourites);
}
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -289,6 +299,12 @@ public class ProfileFragment extends Fragment {
private void fetchProfileDetails() { private void fetchProfileDetails() {
new ProfileFetcher(username.substring(1), profileModel -> { new ProfileFetcher(username.substring(1), profileModel -> {
this.profileModel = profileModel; this.profileModel = profileModel;
final String userIdFromCookie = Utils.getUserIdFromCookie(cookie);
final boolean isSelf = isLoggedIn
&& profileModel != null
&& userIdFromCookie != null
&& userIdFromCookie.equals(profileModel.getId());
favMenuItem.setVisible(isSelf);
setProfileDetails(); setProfileDetails();
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -423,8 +439,8 @@ public class ProfileFragment extends Fragment {
span.setSpan(new StyleSpan(Typeface.BOLD), 0, followingCountStrLen, 0); span.setSpan(new StyleSpan(Typeface.BOLD), 0, followingCountStrLen, 0);
binding.mainFollowing.setText(span); binding.mainFollowing.setText(span);
binding.mainFullName.setText(Utils.isEmpty(profileModel.getName()) ? profileModel binding.mainFullName.setText(Utils.isEmpty(profileModel.getName()) ? profileModel.getUsername()
.getUsername() : profileModel.getName()); : profileModel.getName());
CharSequence biography = profileModel.getBiography(); CharSequence biography = profileModel.getBiography();
binding.mainBiography.setCaptionIsExpandable(true); binding.mainBiography.setCaptionIsExpandable(true);
@ -455,13 +471,10 @@ public class ProfileFragment extends Fragment {
if (isLoggedIn) { if (isLoggedIn) {
final View.OnClickListener followClickListener = v -> { final View.OnClickListener followClickListener = v -> {
// startActivity(new Intent(requireContext(), FollowViewerFragment.class) final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToFollowViewerFragment(
// .putExtra(Constants.EXTRAS_FOLLOWERS, v == binding.mainFollowers) profileId,
// .putExtra(Constants.EXTRAS_NAME, profileModel.getUsername()) v == binding.mainFollowers,
// .putExtra(Constants.EXTRAS_ID, profileId)); profileModel.getUsername());
final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToFollowViewerFragment(profileId,
v == binding.mainFollowers,
profileModel.getUsername());
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);
}; };

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -8,10 +8,14 @@
android:orientation="horizontal"> android:orientation="horizontal">
<FrameLayout <FrameLayout
android:id="@+id/profile_pic_container"
android:layout_width="@dimen/simple_item_picture_size" android:layout_width="@dimen/simple_item_picture_size"
android:layout_height="@dimen/simple_item_picture_size" android:layout_height="@dimen/simple_item_picture_size"
android:gravity="center" android:gravity="center"
android:padding="4dp"> android:padding="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.facebook.drawee.view.SimpleDraweeView <com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/ivProfilePic" android:id="@+id/ivProfilePic"
@ -24,7 +28,8 @@
android:id="@+id/multi_pic_container" android:id="@+id/multi_pic_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"> android:orientation="horizontal"
android:visibility="gone">
<com.facebook.drawee.view.SimpleDraweeView <com.facebook.drawee.view.SimpleDraweeView
android:layout_width="@dimen/simple_item_picture_size_half" android:layout_width="@dimen/simple_item_picture_size_half"
@ -49,74 +54,67 @@
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>
<androidx.constraintlayout.widget.ConstraintLayout <androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent" android:id="@+id/tvUsername"
android:layout_height="wrap_content" android:layout_width="0dp"
android:layout_gravity="center" android:layout_height="0dp"
android:orientation="vertical" android:ellipsize="marquee"
android:padding="8dp"> android:gravity="bottom"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:textColorPrimary"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/tvComment"
app:layout_constraintEnd_toStartOf="@id/tvDate"
app:layout_constraintStart_toEndOf="@id/profile_pic_container"
app:layout_constraintTop_toTopOf="parent"
tools:text="username" />
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvUsername" android:id="@+id/tvDate"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:ellipsize="marquee" android:ellipsize="marquee"
android:gravity="center_vertical" android:gravity="bottom|end"
android:singleLine="true" android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="?android:textColorPrimary" android:textStyle="italic"
android:textStyle="bold" app:layout_constraintBottom_toTopOf="@id/tvComment"
app:layout_constraintEnd_toStartOf="@id/tvDate" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toEndOf="@id/tvUsername"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:text="username" /> tools:text="long date................................" />
<androidx.appcompat.widget.AppCompatTextView <!--<androidx.appcompat.widget.AppCompatImageView-->
android:id="@+id/tvDate" <!-- android:id="@+id/notTextType"-->
android:layout_width="0dp" <!-- android:layout_width="4dp"-->
android:layout_height="0dp" <!-- android:layout_height="4dp"-->
android:ellipsize="marquee" <!-- android:layout_gravity="center_vertical"-->
android:gravity="center_vertical|end" <!-- android:layout_marginEnd="4dp"-->
android:singleLine="true" <!-- android:layout_marginRight="4dp"-->
android:textAppearance="@style/TextAppearance.AppCompat.Caption" <!-- android:visibility="gone"-->
android:textStyle="italic" <!-- app:tint="@color/feed_text_primary_color" />-->
app:layout_constraintBottom_toTopOf="@id/comment_container" <!--<FrameLayout-->
app:layout_constraintEnd_toEndOf="parent" <!-- android:id="@+id/comment_container"-->
app:layout_constraintStart_toEndOf="@id/tvUsername" <!-- android:layout_width="0dp"-->
app:layout_constraintTop_toTopOf="parent" <!-- android:layout_height="wrap_content"-->
tools:text="long date................................" /> <!-- android:orientation="horizontal">-->
<LinearLayout <!-- -->
android:id="@+id/comment_container" <!--</FrameLayout>-->
android:layout_width="0dp" <awais.instagrabber.customviews.RamboTextView
android:layout_height="wrap_content" android:id="@+id/tvComment"
android:orientation="horizontal" android:layout_width="0dp"
app:layout_constraintBottom_toBottomOf="parent" android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_gravity="center_vertical"
app:layout_constraintStart_toStartOf="parent" android:autoLink="web|email"
app:layout_constraintTop_toBottomOf="@id/tvUsername"> android:ellipsize="end"
android:linksClickable="true"
<androidx.appcompat.widget.AppCompatImageView android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:id="@+id/notTextType" app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="4dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_height="4dp" app:layout_constraintHorizontal_bias="0.0"
android:layout_gravity="center_vertical" app:layout_constraintStart_toEndOf="@id/profile_pic_container"
android:layout_marginEnd="4dp" app:layout_constraintTop_toBottomOf="@id/tvUsername"
android:layout_marginRight="4dp" tools:text="comment" />
android:visibility="gone" </androidx.constraintlayout.widget.ConstraintLayout>
app:srcCompat="@android:drawable/ic_notification_overlay"
app:tint="@color/feed_text_primary_color" />
<awais.instagrabber.customviews.RamboTextView
android:id="@+id/tvComment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:autoLink="web|email"
android:ellipsize="end"
android:linksClickable="true"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
tools:text="comment" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/info"
android:icon="@drawable/ic_outline_info_24"
android:title="@string/dm_thread_info"
app:showAsAction="always" />
<item
android:id="@+id/mark_as_seen"
android:icon="@drawable/ic_outline_views_24"
android:title="@string/mark_as_seen"
app:showAsAction="ifRoom" />
</menu>

View File

@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu>
xmlns:app="http://schemas.android.com/apk/res-auto"> <!--<item-->
<item <!-- android:id="@+id/favourites"-->
android:id="@+id/favourites" <!-- android:enabled="true"-->
android:enabled="true" <!-- android:icon="@drawable/ic_star_24"-->
android:icon="@drawable/ic_star_24" <!-- android:title="@string/title_favorites"-->
android:title="@string/title_favorites" <!-- app:showAsAction="ifRoom" />-->
app:showAsAction="ifRoom" />
<!--<item--> <!--<item-->
<!-- android:id="@+id/direct_messages"--> <!-- android:id="@+id/direct_messages"-->

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/favourites"
android:enabled="true"
android:icon="@drawable/ic_star_24"
android:title="@string/title_favorites"
android:visible="false"
app:showAsAction="ifRoom" />
</menu>

View File

@ -249,4 +249,6 @@
<string name="relogin">Relogin</string> <string name="relogin">Relogin</string>
<string name="relogin_summary">Refresh your cookies if facing any issues</string> <string name="relogin_summary">Refresh your cookies if facing any issues</string>
<string name="logout_success">Successfully logged out!</string> <string name="logout_success">Successfully logged out!</string>
<string name="dm_thread_info">Info</string>
<string name="mark_as_seen">Mark as seen</string>
</resources> </resources>