Java Code Examples for com.socks.jiandan.base.BaseActivity

The following examples show how to use com.socks.jiandan.base.BaseActivity. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: JianDan_OkHttpWithVolley   Source File: FileUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 保存图片
 *
 * @param activity
 * @param picUrl
 */
public static void savePicture(Activity activity, String picUrl, LoadFinishCallBack loadFinishCallBack) {

    boolean isSmallPic = false;
    String[] urls = picUrl.split("\\.");
    File cacheFile = ImageLoader.getInstance().getDiskCache().get(picUrl);

    //如果是GIF格式,优先保存GIF动态图,如果不存在,则保存缩略图
    if (!cacheFile.exists()) {
        String cacheUrl = picUrl.replace("mw600", "small").replace("mw1200", "small")
                .replace("large", "small");
        cacheFile = ImageLoader.getInstance().getDiskCache().get(cacheUrl);
        isSmallPic = true;
    }

    File picDir = new File(CacheUtil.getSaveDirPath());

    if (!picDir.exists()) {
        picDir.mkdir();
    }

    final File newFile = new File(picDir, CacheUtil.getSavePicName(cacheFile, urls));

    if (FileUtil.copyTo(cacheFile, newFile)) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(BaseActivity.DATA_IS_SIAMLL_PIC, isSmallPic);
        bundle.putString(BaseActivity.DATA_FILE_PATH, newFile.getAbsolutePath());
        loadFinishCallBack.loadFinish(bundle);
    } else {
        ShowToast.Short(ConstantString.SAVE_FAILED);
    }

}
 
Example 2
Source Project: JianDan   Source File: FileUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 保存图片
 *
 * @param activity
 * @param picUrl
 */
public static void savePicture(Activity activity, String picUrl, LoadFinishCallBack loadFinishCallBack) {

    boolean isSmallPic = false;
    String[] urls = picUrl.split("\\.");
    File cacheFile = ImageLoader.getInstance().getDiskCache().get(picUrl);

    //如果是GIF格式,优先保存GIF动态图,如果不存在,则保存缩略图
    if (!cacheFile.exists()) {
        String cacheUrl = picUrl.replace("mw600", "small").replace("mw1200", "small")
                .replace("large", "small");
        cacheFile = ImageLoader.getInstance().getDiskCache().get(cacheUrl);
        isSmallPic = true;
    }

    File picDir = new File(CacheUtil.getSaveDirPath());

    if (!picDir.exists()) {
        picDir.mkdir();
    }

    final File newFile = new File(picDir, CacheUtil.getSavePicName(cacheFile, urls));

    if (FileUtil.copyTo(cacheFile, newFile)) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(BaseActivity.DATA_IS_SIAMLL_PIC, isSmallPic);
        bundle.putString(BaseActivity.DATA_FILE_PATH, newFile.getAbsolutePath());
        loadFinishCallBack.loadFinish(bundle);
    } else {
        ShowToast.Short(ConstantString.SAVE_FAILED);
    }

}
 
Example 3
Source Project: JianDanRxJava   Source File: FileUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void savePicture(String picUrl, LoadFinishCallBack<Bundle> loadFinishCallBack) {

        boolean isSmallPic = false;
        String[] urls = picUrl.split("\\.");
        File cacheFile = ImageLoader.getInstance().getDiskCache().get(picUrl);

        //如果是GIF格式,优先保存GIF动态图,如果不存在,则保存缩略图
        if (!cacheFile.exists()) {
            String cacheUrl = picUrl.replace("mw600", "small").replace("mw1200", "small")
                    .replace("large", "small");
            cacheFile = ImageLoader.getInstance().getDiskCache().get(cacheUrl);
            isSmallPic = true;
        }

        File picDir = new File(CacheUtil.getSaveDirPath());

        if (!picDir.exists()) {

            if (picDir.mkdir()) {
                final File newFile = new File(picDir, CacheUtil.getSavePicName(cacheFile, urls));
                if (FileUtil.copyTo(cacheFile, newFile)) {
                    Bundle bundle = new Bundle();
                    bundle.putBoolean(BaseActivity.DATA_IS_SMALL_PIC, isSmallPic);
                    bundle.putString(BaseActivity.DATA_FILE_PATH, newFile.getAbsolutePath());
                    loadFinishCallBack.loadFinish(bundle);
                } else {
                    ToastHelper.Short(ConstantString.SAVE_FAILED);
                }
            }
        }
    }
 
Example 4
Source Project: JianDanRxJava   Source File: IntentHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static void toImageDetailActivity(Context context, Picture picture){
    Intent intent = new Intent(context, ImageDetailActivity.class);

    intent.putExtra(BaseActivity.DATA_IMAGE_AUTHOR, picture.getComment_author());
    intent.putExtra(BaseActivity.DATA_IMAGE_URL, picture.getPics());
    intent.putExtra(BaseActivity.DATA_IMAGE_ID, picture.getComment_ID());
    intent.putExtra(BaseActivity.DATA_THREAD_KEY, "comment-" + picture.getComment_ID());

    if (picture.getPics()[0].endsWith(".gif")) {
        intent.putExtra(BaseActivity.DATA_IS_NEED_WEB_VIEW, true);
    }

    context.startActivity(intent);
}
 
Example 5
Source Project: JianDanRxJava   Source File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public PictureAdapter(BaseActivity activity, LoadResultCallBack loadResultCallBack, LoadFinishCallBack<Object> loadFinisCallBack, int type) {
    mActivity = activity;
    mType = type;
    mLoadFinisCallBack = loadFinisCallBack;
    mLoadResultCallBack = loadResultCallBack;
    mPictures = new ArrayList<>();
    isWifiConnected = NetWorkUtil.isWifiConnected(mActivity);
}
 
Example 6
Source Project: JianDanRxJava   Source File: FreshNewsAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public FreshNewsAdapter(BaseActivity activity, LoadFinishCallBack<Object> loadFinisCallBack, LoadResultCallBack loadResultCallBack) {
    this.mActivity = activity;
    this.isLargeMode = SPHelper.getBoolean(SettingFragment.ENABLE_FRESH_BIG, true);
    this.mLoadFinisCallBack = loadFinisCallBack;
    this.mLoadResultCallBack = loadResultCallBack;
    mFreshNews = new ArrayList<>();

    int loadingResource = isLargeMode ? R.drawable.ic_loading_large : R.drawable.ic_loading_small;
    options = ImageLoadProxy.getOptions4PictureList(loadingResource);
}
 
Example 7
Source Project: JianDanRxJava   Source File: CommentAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public CommentAdapter(BaseActivity activity, String thread_key, boolean isFromFreshNews, LoadResultCallBack loadResultCallBack) {
    mActivity = activity;
    mThread_key = thread_key;
    mIsFromFreshNews = isFromFreshNews;
    mLoadResultCallBack = loadResultCallBack;
    if (mIsFromFreshNews) {
        mCommentators4FreshNews = new ArrayList<>();
    } else {
        mCommentators = new ArrayList<>();
    }
}
 
Example 8
Source Project: JianDanRxJava   Source File: FreshNewsFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mAdapter = new FreshNewsAdapter((BaseActivity) mContext, mRecyclerView, this);
    mRecyclerView.setAdapter(mAdapter);
    mAdapter.loadFirst();
    loading.start();
}
 
Example 9
Source Project: JianDan_OkHttp   Source File: FileUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 保存图片
 *
 * @param activity
 * @param picUrl
 */
public static void savePicture(Activity activity, String picUrl, LoadFinishCallBack loadFinishCallBack) {

    boolean isSmallPic = false;
    String[] urls = picUrl.split("\\.");
    File cacheFile = ImageLoader.getInstance().getDiskCache().get(picUrl);

    //如果是GIF格式,优先保存GIF动态图,如果不存在,则保存缩略图
    if (!cacheFile.exists()) {
        String cacheUrl = picUrl.replace("mw600", "small").replace("mw1200", "small")
                .replace("large", "small");
        cacheFile = ImageLoader.getInstance().getDiskCache().get(cacheUrl);
        isSmallPic = true;
    }

    File picDir = new File(CacheUtil.getSaveDirPath());

    if (!picDir.exists()) {
        picDir.mkdir();
    }

    final File newFile = new File(picDir, CacheUtil.getSavePicName(cacheFile, urls));

    if (FileUtil.copyTo(cacheFile, newFile)) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(BaseActivity.DATA_IS_SIAMLL_PIC, isSmallPic);
        bundle.putString(BaseActivity.DATA_FILE_PATH, newFile.getAbsolutePath());
        loadFinishCallBack.loadFinish(bundle);
    } else {
        ShowToast.Short(ConstantString.SAVE_FAILED);
    }

}
 
Example 10
Source Project: JianDanRxJava   Source File: IntentHelper.java    License: Apache License 2.0 4 votes vote down vote up
public static void toCommentListActivity(Context context, String id) {
    Intent intent = new Intent(context, CommentListActivity.class);
    intent.putExtra(BaseActivity.DATA_THREAD_ID, id);
    intent.putExtra(BaseActivity.DATA_IS_FROM_FRESH_NEWS, true);
    context.startActivity(intent);
}
 
Example 11
Source Project: JianDanRxJava   Source File: JokeAdapter.java    License: Apache License 2.0 4 votes vote down vote up
public JokeAdapter(BaseActivity activity, LoadFinishCallBack<Object> loadFinisCallBack, LoadResultCallBack loadResultCallBack) {
    mActivity = activity;
    mLoadFinisCallBack = loadFinisCallBack;
    mLoadResultCallBack = loadResultCallBack;
    mJokes = new ArrayList<>();
}
 
Example 12
Source Project: JianDanRxJava   Source File: PictureAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(final PictureViewHolder holder, final int position) {

    final Picture picture = mPictures.get(position);
    String picUrl = picture.getPics()[0];

    if (picUrl.endsWith(".gif")) {
        holder.img_gif.setVisibility(View.VISIBLE);
        //非WIFI网络情况下,GIF图只加载缩略图,详情页才加载真实图片
        if (!isWifiConnected) {
            picUrl = picUrl.replace("mw600", "small").replace("mw1200", "small").replace
                    ("large", "small");
        }
    } else {
        holder.img_gif.setVisibility(View.GONE);
    }

    holder.progress.setProgress(0);
    holder.progress.setVisibility(View.VISIBLE);

    ImageLoadProxy.displayImageList(picUrl, holder.img, R.drawable.ic_loading_large, new
                    SimpleImageLoadingListener() {
                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                            super.onLoadingComplete(imageUri, view, loadedImage);
                            holder.progress.setVisibility(View.GONE);
                        }
                    },
            (imageUri, view, current, total) -> holder.progress.setProgress((int) (current * 100f / total)));

    if (TextUtil.isNull(picture.getText_content().trim())) {
        holder.tv_content.setVisibility(View.GONE);
    } else {
        holder.tv_content.setVisibility(View.VISIBLE);
        holder.tv_content.setText(picture.getText_content().trim());
    }

    holder.img.setOnClickListener(v -> IntentHelper.toImageDetailActivity(mActivity, picture));

    holder.tv_author.setText(picture.getComment_author());
    holder.tv_time.setText(String2TimeUtil.dateString2GoodExperienceFormat(picture.getComment_date()));
    holder.tv_like.setText(picture.getVote_positive());
    holder.tv_comment_count.setText(picture.getComment_counts());

    //用于恢复默认的文字
    holder.tv_like.setTypeface(Typeface.DEFAULT);
    holder.tv_like.setTextColor(mActivity.getResources().getColor(
            secondary_text_default_material_light));
    holder.tv_support_des.setTextColor(mActivity.getResources().getColor(
            secondary_text_default_material_light));

    holder.tv_unlike.setText(picture.getVote_negative());
    holder.tv_unlike.setTypeface(Typeface.DEFAULT);
    holder.tv_unlike.setTextColor(mActivity.getResources().getColor(
            secondary_text_default_material_light));
    holder.tv_un_support_des.setTextColor(mActivity.getResources().getColor(
            secondary_text_default_material_light));

    holder.img_share.setOnClickListener(v -> new MaterialDialog.Builder(mActivity)
            .items(R.array.picture_dialog)
            .backgroundColor(mActivity.getResources().getColor(JDApplication.COLOR_OF_DIALOG))
            .contentColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
            .itemsCallback((dialog, view, which, text) -> {

                switch (which) {
                    case 0:
                        ShareUtil.sharePicture(mActivity, picture
                                .getPics()[0]);
                        break;
                    case 1:
                        FileUtil.savePicture(picture
                                .getPics()[0], mSaveFileCallBack);
                        break;
                }
            })
            .show());

    holder.ll_comment.setOnClickListener(v -> {
        Intent intent = new Intent(mActivity, CommentListActivity.class);
        intent.putExtra(BaseActivity.DATA_THREAD_KEY, "comment-" + picture.getComment_ID());
        mActivity.startActivity(intent);
    });

    setAnimation(holder.card, position);

}
 
Example 13
Source Project: JianDanRxJava   Source File: VideoAdapter.java    License: Apache License 2.0 4 votes vote down vote up
public VideoAdapter(BaseActivity activity, LoadResultCallBack loadResultCallBack, LoadFinishCallBack<Object> loadFinisCallBack) {
    mActivity = activity;
    mLoadFinisCallBack = loadFinisCallBack;
    mLoadResultCallBack = loadResultCallBack;
    mVideos = new ArrayList<>();
}