Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.

Long click options menu for in-text links #11

Merged
merged 1 commit into from
Jan 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions app/src/main/java/me/saket/dank/di/RootModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,27 @@
import android.net.ConnectivityManager;
import android.os.Build;
import android.preference.PreferenceManager;
import android.view.Gravity;

import com.f2prateek.rx.preferences2.RxSharedPreferences;
import com.facebook.stetho.okhttp3.StethoInterceptor;
import com.squareup.moshi.Moshi;
import com.squareup.sqlbrite2.BriteDatabase;
import com.squareup.sqlbrite2.SqlBrite;
import dagger.Module;
import dagger.Provides;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.moshi.MoshiConverterFactory;
import timber.log.Timber;

import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import io.reactivex.schedulers.Schedulers;
import me.saket.dank.BuildConfig;
import me.saket.dank.R;
import me.saket.dank.data.DankSqliteOpenHelper;
Expand All @@ -32,17 +39,12 @@
import me.saket.dank.ui.UrlRouter;
import me.saket.dank.ui.authentication.LoginActivity;
import me.saket.dank.ui.submission.DraftStore;
import me.saket.dank.ui.submission.LinkOptionsPopup;
import me.saket.dank.urlparser.Link;
import me.saket.dank.urlparser.RedditUserLink;
import me.saket.dank.urlparser.UrlParser;
import me.saket.dank.utils.DankLinkMovementMethod;
import me.saket.dank.utils.OkHttpWholesomeAuthIntercepter;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.moshi.MoshiConverterFactory;
import timber.log.Timber;

@Module
public class RootModule {
Expand Down Expand Up @@ -163,6 +165,13 @@ DankLinkMovementMethod provideBetterLinkMovementMethod(UrlRouter urlRouter, UrlP
}
return true;
});
linkMovementMethod.setOnLinkLongClickListener((textView, url) -> {
Link parsedLink = urlParser.parse(url);
Point touchCoordinates = linkMovementMethod.getLastTouchCoordinates();
LinkOptionsPopup linkOptionsPopup = new LinkOptionsPopup(textView.getContext(), parsedLink);
linkOptionsPopup.showAtLocation(textView, Gravity.TOP | Gravity.START, touchCoordinates);
return true;
});
return linkMovementMethod;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
public class DankLinkMovementMethod extends BetterLinkMovementMethod {

private Point clickedUrlCoordinates;
private Point touchCoordinates;

public static DankLinkMovementMethod newInstance() {
return new DankLinkMovementMethod();
Expand All @@ -24,11 +25,17 @@ public Point getLastUrlClickCoordinates() {
return clickedUrlCoordinates;
}

public Point getLastTouchCoordinates() {
return touchCoordinates;
}

@Override
public boolean onTouchEvent(TextView view, Spannable text, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
// A link is potentially going to be clicked.
clickedUrlCoordinates = new Point((int) event.getRawX(), (int) event.getRawY());
} else if (event.getAction() == MotionEvent.ACTION_DOWN) {
touchCoordinates = new Point((int) event.getRawX(), (int) event.getRawY());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can clickedUrlCoordinates not be used here?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm good point, didn't think of that. I guess it should work.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 58cb38d

}
return super.onTouchEvent(view, text, event);
}
Expand Down