Browse Source

Fix DM fragments, comment out deprecated activities

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
cc9348d8c5
  1. 8
      app/src/main/java/awais/instagrabber/InstaGrabberApplication.java
  2. 3042
      app/src/main/java/awais/instagrabber/MainHelper.java
  3. 188
      app/src/main/java/awais/instagrabber/activities/DirectMessagesActivity.java
  4. 3
      app/src/main/java/awais/instagrabber/activities/MainActivity.java
  5. 1214
      app/src/main/java/awais/instagrabber/activities/MainActivityBackup.java
  6. 9
      app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java
  7. 1572
      app/src/main/java/awais/instagrabber/activities/PostViewer.java
  8. 1900
      app/src/main/java/awais/instagrabber/activities/ProfileViewer.java
  9. 22
      app/src/main/java/awais/instagrabber/adapters/viewholder/DirectMessageInboxItemViewHolder.java
  10. 10
      app/src/main/java/awais/instagrabber/dialogs/QuickAccessDialog.java
  11. 5
      app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java
  12. 6
      app/src/main/java/awais/instagrabber/fragments/LocationFragment.java
  13. 2
      app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
  14. 86
      app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java
  15. 117
      app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java
  16. 4
      app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java
  17. 27
      app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
  18. 78
      app/src/main/res/layout/layout_dm_inbox_item.xml
  19. 14
      app/src/main/res/menu/dm_thread_menu.xml
  20. 15
      app/src/main/res/menu/main_menu.xml
  21. 12
      app/src/main/res/menu/profile_menu.xml
  22. 2
      app/src/main/res/values/strings.xml

8
app/src/main/java/awais/instagrabber/InstaGrabberApplication.java

@ -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 {

3042
app/src/main/java/awais/instagrabber/MainHelper.java
File diff suppressed because it is too large
View File

188
app/src/main/java/awais/instagrabber/activities/DirectMessagesActivity.java

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

3
app/src/main/java/awais/instagrabber/activities/MainActivity.java

@ -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;

1214
app/src/main/java/awais/instagrabber/activities/MainActivityBackup.java
File diff suppressed because it is too large
View File

9
app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java

@ -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)
startActivity(new Intent(getApplicationContext(), PostViewer.class)
.putExtra(Constants.EXTRAS_POST, new PostModel(notificationModel.getShortcode(), false)));
else if (which == 1 && commentDialogList.length == 2) {
// startActivity(new Intent(getApplicationContext(), PostViewer.class)
// .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> {

1572
app/src/main/java/awais/instagrabber/activities/PostViewer.java
File diff suppressed because it is too large
View File

1900
app/src/main/java/awais/instagrabber/activities/ProfileViewer.java
File diff suppressed because it is too large
View File

22
app/src/main/java/awais/instagrabber/adapters/viewholder/DirectMessageInboxItemViewHolder.java

@ -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;
@ -49,15 +54,28 @@ public final class DirectMessageInboxItemViewHolder extends RecyclerView.ViewHol
for (int i = 0; i < Math.min(3, users.length); ++i) { for (int i = 0; i < Math.min(3, users.length); ++i) {
multipleProfilePics[i].setImageURI(users[i].getSdProfilePic()); multipleProfilePics[i].setImageURI(users[i].getSdProfilePic());
} }
} else {
final String uriString = users.length == 1 ? users[0].getSdProfilePic() : null;
if (uriString == null) {
binding.ivProfilePic.setVisibility(View.GONE);
} else { } else {
binding.ivProfilePic.setVisibility(View.VISIBLE); binding.ivProfilePic.setVisibility(View.VISIBLE);
multipleProfilePicsContainer.setVisibility(View.GONE); multipleProfilePicsContainer.setVisibility(View.GONE);
binding.ivProfilePic.setImageURI(users.length == 1 ? users[0].getSdProfilePic() : null);
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) {

10
app/src/main/java/awais/instagrabber/dialogs/QuickAccessDialog.java

@ -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) {
MainActivityBackup.scanHack.onResult(((DataBox.FavoriteModel) tag).getQuery());
dismiss();
}
// if (MainActivityBackup.scanHack != null) {
// MainActivityBackup.scanHack.onResult(((DataBox.FavoriteModel) tag).getQuery());
// 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;

5
app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java

@ -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;

6
app/src/main/java/awais/instagrabber/fragments/LocationFragment.java

@ -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();

2
app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java

@ -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();

86
app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java

@ -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)));
memberAdapter = new DirectMessageMembersAdapter(threadModel.getUsers(), adminList, requireContext(), amAdmin ? clickListener : basicClickListener);
final String userIdFromCookie = Utils.getUserIdFromCookie(cookie);
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(
new Intent(requireContext(), ProfileViewer.class)
.putExtra(Constants.EXTRAS_USERNAME, model.getUsername())
);
// startActivity(new Intent(requireContext(), ProfileViewer.class)
// .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(
new Intent(requireContext(), ProfileViewer.class)
.putExtra(Constants.EXTRAS_USERNAME, model.getUsername())
);
}
else {
new AlertDialog.Builder(requireContext()).setAdapter(
new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, new String[]{
// startActivity(new Intent(requireContext(), ProfileViewer.class)
// .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), getString(R.string.open_profile),
getString(R.string.dms_action_kick), getString(R.string.dms_action_kick),
}),
(d,w) -> {
if (w == 0)
startActivity(
new Intent(requireContext(), ProfileViewer.class)
.putExtra(Constants.EXTRAS_USERNAME, model.getUsername())
);
else if (w == 1) {
});
final DialogInterface.OnClickListener clickListener = (d, w) -> {
if (w == 0) {
// startActivity(new Intent(requireContext(), ProfileViewer.class)
// .putExtra(Constants.EXTRAS_USERNAME, model.getUsername()));
} else if (w == 1) {
new ChangeSettings().execute("remove_users", model.getId()); new ChangeSettings().execute("remove_users", model.getId());
onRefresh(); onRefresh();
} }
}).show();
};
new AlertDialog.Builder(requireContext())
.setAdapter(adapter, clickListener)
.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,9 +188,7 @@ 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) -> {
new ChangeSettings().execute("leave");
})
.setPositiveButton(R.string.yes, (x, y) -> new ChangeSettings().execute("leave"))
.setNegativeButton(R.string.no, null) .setNegativeButton(R.string.no, null)
.show(); .show();
}); });
@ -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,10 +222,10 @@ 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", "'")
@ -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();
} }
} }
} }

117
app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java

@ -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) {
if (root != null) {
shouldRefresh = false;
return root;
}
binding = FragmentDirectMessagesThreadBinding.inflate(inflater, container, false); binding = FragmentDirectMessagesThreadBinding.inflate(inflater, container, false);
final FragmentContainerView containerTwo = (FragmentContainerView) container.getParent();
// 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) {
root = binding.getRoot();
return root; 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);
} }
} }
} }

4
app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java

@ -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;

27
app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java

@ -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
.getUsername() : profileModel.getName());
binding.mainFullName.setText(Utils.isEmpty(profileModel.getName()) ? profileModel.getUsername()
: profileModel.getName());
CharSequence biography = profileModel.getBiography(); CharSequence biography = profileModel.getBiography();
binding.mainBiography.setCaptionIsExpandable(true); binding.mainBiography.setCaptionIsExpandable(true);
@ -455,11 +471,8 @@ 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)
// .putExtra(Constants.EXTRAS_FOLLOWERS, v == binding.mainFollowers)
// .putExtra(Constants.EXTRAS_NAME, profileModel.getUsername())
// .putExtra(Constants.EXTRAS_ID, profileId));
final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToFollowViewerFragment(profileId,
final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToFollowViewerFragment(
profileId,
v == binding.mainFollowers, v == binding.mainFollowers,
profileModel.getUsername()); profileModel.getUsername());
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);

78
app/src/main/res/layout/layout_dm_inbox_item.xml

@ -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,25 +54,19 @@
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:padding="8dp">
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvUsername" android:id="@+id/tvUsername"
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"
android:singleLine="true" android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/tvComment"
app:layout_constraintEnd_toStartOf="@id/tvDate" app:layout_constraintEnd_toStartOf="@id/tvDate"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@id/profile_pic_container"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:text="username" /> tools:text="username" />
@ -76,47 +75,46 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:ellipsize="marquee" android:ellipsize="marquee"
android:gravity="center_vertical|end"
android:gravity="bottom|end"
android:singleLine="true" android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textStyle="italic" android:textStyle="italic"
app:layout_constraintBottom_toTopOf="@id/comment_container"
app:layout_constraintBottom_toTopOf="@id/tvComment"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvUsername" app:layout_constraintStart_toEndOf="@id/tvUsername"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:text="long date................................" /> tools:text="long date................................" />
<LinearLayout
android:id="@+id/comment_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvUsername">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/notTextType"
android:layout_width="4dp"
android:layout_height="4dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:visibility="gone"
app:srcCompat="@android:drawable/ic_notification_overlay"
app:tint="@color/feed_text_primary_color" />
<!--<androidx.appcompat.widget.AppCompatImageView-->
<!-- android:id="@+id/notTextType"-->
<!-- android:layout_width="4dp"-->
<!-- android:layout_height="4dp"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:layout_marginEnd="4dp"-->
<!-- android:layout_marginRight="4dp"-->
<!-- android:visibility="gone"-->
<!-- app:tint="@color/feed_text_primary_color" />-->
<!--<FrameLayout-->
<!-- android:id="@+id/comment_container"-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:orientation="horizontal">-->
<!-- -->
<!--</FrameLayout>-->
<awais.instagrabber.customviews.RamboTextView <awais.instagrabber.customviews.RamboTextView
android:id="@+id/tvComment" android:id="@+id/tvComment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:autoLink="web|email" android:autoLink="web|email"
android:ellipsize="end" android:ellipsize="end"
android:linksClickable="true" android:linksClickable="true"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" android:textAppearance="@style/TextAppearance.AppCompat.Caption"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@id/profile_pic_container"
app:layout_constraintTop_toBottomOf="@id/tvUsername"
tools:text="comment" /> tools:text="comment" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

14
app/src/main/res/menu/dm_thread_menu.xml

@ -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>

15
app/src/main/res/menu/main_menu.xml

@ -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"
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"
app:showAsAction="ifRoom" />
<menu>
<!--<item-->
<!-- android:id="@+id/favourites"-->
<!-- android:enabled="true"-->
<!-- android:icon="@drawable/ic_star_24"-->
<!-- android:title="@string/title_favorites"-->
<!-- app:showAsAction="ifRoom" />-->
<!--<item--> <!--<item-->
<!-- android:id="@+id/direct_messages"--> <!-- android:id="@+id/direct_messages"-->

12
app/src/main/res/menu/profile_menu.xml

@ -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>

2
app/src/main/res/values/strings.xml

@ -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>
Loading…
Cancel
Save