Search in sources :

Example 1 with PostActivity

use of me.yluo.ruisiapp.activity.PostActivity in project Ruisi by freedom10086.

the class LinkClickHandler method handleClick.

public static void handleClick(final Context context, String url) {
    Log.d("handle the link", url);
    // 点击了图片
    if (url.contains("from=album")) {
        ViewImgActivity.open(context, url);
    } else if (url.contains("forum.php?mod=viewthread&tid=") || url.contains("forum.php?mod=redirect&goto=findpost")) {
        // 帖子
        PostActivity.open(context, url, null);
    } else if (url.contains("home.php?mod=space&uid=")) {
        // 用户
        String imageUrl = UrlUtils.getAvaterurlb(url);
        UserDetailActivity.open(context, "name", imageUrl, "");
    } else if (url.contains("forum.php?mod=post&action=newthread")) {
        // 发帖链接
        context.startActivity(new Intent(context, NewPostActivity.class));
    } else if (url.contains("member.php?mod=logging&action=login")) {
        // 登陆
        LoginActivity.open(context);
    } else if (url.contains("forum.php?mod=forumdisplay&fid=")) {
        int fid = GetId.getFroumFid(url);
        PostsActivity.open(context, fid, "分区帖子");
    } else if (url.startsWith("forum.php?mod=post&action=reply")) {
        // 回复
        if (context instanceof PostActivity) {
            PostActivity a = (PostActivity) context;
            a.showReplyKeyboard();
        }
    } else if (url.contains("forum.php?mod=attachment")) {
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            // 没有权限
            new AlertDialog.Builder(context).setTitle("权限错误").setMessage("没有写入内部存储的权限,无法下载").setPositiveButton("授权", (dialog, which) -> {
                ActivityCompat.requestPermissions((BaseActivity) context, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
            // 请求结果在onRequestPermissionsResult返回
            }).setNegativeButton("取消", null).setCancelable(true).create().show();
        } else {
            // 启动下载服务
            final String finalUrl = url;
            new AlertDialog.Builder(context).setTitle("下载附件").setMessage("你要开始下载此附件吗?").setPositiveButton("下载", (dialog, which) -> {
                Intent intent = new Intent(context, DownloadService.class);
                intent.putExtra("download_url", finalUrl);
                context.startService(intent);
            }).setNegativeButton("取消", null).setCancelable(true).create().show();
        }
    } else if (url.startsWith(VOTE_URL)) {
        // 投票
        if (context instanceof PostActivity) {
            PostActivity a = (PostActivity) context;
            a.showVoteView();
        }
    } else {
        if (!url.startsWith("http")) {
            url = App.getBaseUrl() + url;
        }
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
        CustomTabsIntent customTabsIntent = builder.build();
        String packageName = TabsHelper.getPackageNameToUse(context);
        if (packageName == null) {
            // 不支持 chrometabs
            Log.d("link click", "not support chrome tabs");
            IntentUtils.openBroswer(context, url);
        } else {
            customTabsIntent.intent.setPackage(packageName);
            customTabsIntent.launchUrl(context, Uri.parse(url));
        }
    }
}
Also used : Context(android.content.Context) PostsActivity(me.yluo.ruisiapp.activity.PostsActivity) UserDetailActivity(me.yluo.ruisiapp.activity.UserDetailActivity) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) ContextCompat(android.support.v4.content.ContextCompat) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) ViewImgActivity(me.yluo.ruisiapp.activity.ViewImgActivity) ActivityCompat(android.support.v4.app.ActivityCompat) R(me.yluo.ruisiapp.R) NewPostActivity(me.yluo.ruisiapp.activity.NewPostActivity) Manifest(android.Manifest) DownloadService(me.yluo.ruisiapp.downloadfile.DownloadService) AlertDialog(android.support.v7.app.AlertDialog) BaseActivity(me.yluo.ruisiapp.activity.BaseActivity) LoginActivity(me.yluo.ruisiapp.activity.LoginActivity) PostActivity(me.yluo.ruisiapp.activity.PostActivity) Log(android.util.Log) App(me.yluo.ruisiapp.App) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) BaseActivity(me.yluo.ruisiapp.activity.BaseActivity) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) NewPostActivity(me.yluo.ruisiapp.activity.NewPostActivity) PostActivity(me.yluo.ruisiapp.activity.PostActivity) DownloadService(me.yluo.ruisiapp.downloadfile.DownloadService)

Aggregations

Manifest (android.Manifest)1 Context (android.content.Context)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 Uri (android.net.Uri)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 ActivityCompat (android.support.v4.app.ActivityCompat)1 ContextCompat (android.support.v4.content.ContextCompat)1 AlertDialog (android.support.v7.app.AlertDialog)1 Log (android.util.Log)1 App (me.yluo.ruisiapp.App)1 R (me.yluo.ruisiapp.R)1 BaseActivity (me.yluo.ruisiapp.activity.BaseActivity)1 LoginActivity (me.yluo.ruisiapp.activity.LoginActivity)1 NewPostActivity (me.yluo.ruisiapp.activity.NewPostActivity)1 PostActivity (me.yluo.ruisiapp.activity.PostActivity)1 PostsActivity (me.yluo.ruisiapp.activity.PostsActivity)1 UserDetailActivity (me.yluo.ruisiapp.activity.UserDetailActivity)1 ViewImgActivity (me.yluo.ruisiapp.activity.ViewImgActivity)1 DownloadService (me.yluo.ruisiapp.downloadfile.DownloadService)1