Как сделать полноэкранный образ и можно перемещать при нажатии на элемент в RecyclerView, как PlayStore? - AndroidX - PullRequest
0 голосов
/ 22 октября 2019

// Я хочу сделать полноэкранное изображение при щелчке элемента в RecyclerView, как я могу это сделать? This is my App, there has screenshot of the game

// это из playstore при нажатии на изображение It's look like going to Another Activity and the image can be zommable and swipable to another image

// Это Activity.java

public class TabDetailGamesActivity extends AppCompatActivity {

TextView TVID;
TextView TVGameName;
TextView TVDeveloperName;
TextView TVGameSize;
TextView TVShortDescription;
ImageView IMGGameImage;

//1
ArrayList<ModelDetailSectionGamesScreenshot> modelDetailSectionGamesScreenshots = new ArrayList<ModelDetailSectionGamesScreenshot>();
AdapterDetailSectionGamesScreenshot adapterDetailSectionGamesScreenshot;

//ModelData
List<ModelDetailSingleGamesScreenshot> modelDetailSingleGamesScreenshots;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activitydetail_tabgames);



    TVID = findViewById(R.id.TV_ID);
    TVGameName = findViewById(R.id.TV_GameName);
    TVDeveloperName = findViewById(R.id.TV_DeveloperName);
    TVGameSize = findViewById(R.id.TV_GameSize);
    TVShortDescription = findViewById(R.id.TV_ShortDescription);
    IMGGameImage = findViewById(R.id.IMG_GameImage);


    //Receive data
    Intent intent = getIntent();

    int ID = intent.getExtras().getInt("IDPKG");
    String GameName = intent.getExtras().getString("GameNamePKG");
    String DeveloperName = intent.getExtras().getString("DeveloperNamePKG");
    String GameSize = intent.getExtras().getString("GameSizePKG");
    String ShortDescription = intent.getExtras().getString("ShortDescriptionPKG");
    int GameImage = intent.getExtras().getInt("GameImagePKG");


    //Setting Values
    TVID.setText(""+ID);
    TVGameName.setText(GameName);
    TVDeveloperName.setText(DeveloperName);
    TVGameSize.setText(GameSize);
    TVShortDescription.setText(ShortDescription);
    IMGGameImage.setImageResource(GameImage);

    //Toolbar
    Toolbar toolbar_login = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar_login);
    getSupportActionBar().setTitle("Berada Didalam " + GameName + " Tab Games");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);


    //1
    createDummyData1();

    RecyclerView RecyclerViewDetailSingleGamesScreenshot = findViewById(R.id.RecyclerViewDetail_Single_GamesScreenshot);
    RecyclerViewDetailSingleGamesScreenshot.setHasFixedSize(true);
    adapterDetailSectionGamesScreenshot = new AdapterDetailSectionGamesScreenshot(TabDetailGamesActivity.this, modelDetailSectionGamesScreenshots);
    RecyclerViewDetailSingleGamesScreenshot.setLayoutManager(new LinearLayoutManager(TabDetailGamesActivity.this, LinearLayoutManager.VERTICAL, false));
    RecyclerViewDetailSingleGamesScreenshot.setAdapter(adapterDetailSectionGamesScreenshot);
    //Optimized
    RecyclerViewDetailSingleGamesScreenshot.setHasFixedSize(true);
    RecyclerViewDetailSingleGamesScreenshot.setItemViewCacheSize(20);



    }

public void createDummyData1() {
    ModelDetailSectionGamesScreenshot modelDetailSectionGamesScreenshotX = new ModelDetailSectionGamesScreenshot();
    modelDetailSectionGamesScreenshotX.setHeaderTitle("Screenshot");

    ArrayList<ModelDetailSingleGamesScreenshot> modelDetailSingleGamesScreenshots = new ArrayList<ModelDetailSingleGamesScreenshot>();
    modelDetailSingleGamesScreenshots.add(new ModelDetailSingleGamesScreenshot(1, R.drawable.ss1));
    modelDetailSingleGamesScreenshots.add(new ModelDetailSingleGamesScreenshot(2, R.drawable.ss2));
    modelDetailSingleGamesScreenshots.add(new ModelDetailSingleGamesScreenshot(3, R.drawable.ss3));
    modelDetailSingleGamesScreenshots.add(new ModelDetailSingleGamesScreenshot(4, R.drawable.ss4));


    modelDetailSectionGamesScreenshotX.setAllItemsInSection(modelDetailSingleGamesScreenshots);
    modelDetailSectionGamesScreenshots.add(modelDetailSectionGamesScreenshotX);
}



@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            //GoBack
            onBackPressed();

            // todo: goto back activity from here
            /*Intent intent = new Intent(TabMoreHotActivity.this, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish();*/
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}
}

// Секция адаптера

public class AdapterDetailSectionGamesScreenshot extends RecyclerView.Adapter{

private Context mContext;
private ArrayList<ModelDetailSectionGamesScreenshot> modelDetailSectionGamesScreenshots;

public AdapterDetailSectionGamesScreenshot(Context mContext, ArrayList<ModelDetailSectionGamesScreenshot> modelDetailSectionGamesScreenshots) {
    this.mContext = mContext;
    this.modelDetailSectionGamesScreenshots = modelDetailSectionGamesScreenshots;
}

@Override
public SectionDetailGamesScreenshotViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.itemdetail_section_gamesscreenshot, null);
    return new SectionDetailGamesScreenshotViewHolder(v);
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

    final SectionDetailGamesScreenshotViewHolder sectionDetailGamesScreenshotViewHolder = (SectionDetailGamesScreenshotViewHolder) holder;
    ModelDetailSectionGamesScreenshot modelDetailSectionGamesScreenshotX = modelDetailSectionGamesScreenshots.get(position);

    //Set
    sectionDetailGamesScreenshotViewHolder.TVSectionTitle.setText(modelDetailSectionGamesScreenshotX.getHeaderTitle());

    ArrayList singleSectionItems = modelDetailSectionGamesScreenshotX.getAllItemsInSection();

    //Masukin semua adapter dari single, ke AdapterSection menjadi Bundle untuk digunakan
    AdapterDetailSingleGamesScreenshot itemListDataAdapter = new AdapterDetailSingleGamesScreenshot(mContext, singleSectionItems);


    final String sectionTitle = modelDetailSectionGamesScreenshotX.getHeaderTitle();
    sectionDetailGamesScreenshotViewHolder.BTNDetailGamesScreenshot.setOnClickListener(
            new View.OnClickListener() { @Override public void onClick(View v) {
                Toast.makeText(v.getContext(), "click event on more, "+sectionTitle, Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(mContext, TabDetailMoreGamesScreenshotActivity.class);
                // here you create put extra in new intent not the intent that you created

                intent.putExtra("DetailMoreGamesScreenshot", modelDetailSectionGamesScreenshots.get(position).getAllItemsInSection());
                mContext.startActivity(intent);

            } });




    /*Glide.with(mContext)
            .load(feedItem.getImageURL())
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .centerCrop()
            .error(R.drawable.bg)
            .into(feedListRowHolder.thumbView);*/

    //SetRecyclerView
    sectionDetailGamesScreenshotViewHolder.RecyclerViewDetailSectionGamesScreenshot.setHasFixedSize(true);
    sectionDetailGamesScreenshotViewHolder.RecyclerViewDetailSectionGamesScreenshot.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
    sectionDetailGamesScreenshotViewHolder.RecyclerViewDetailSectionGamesScreenshot.setAdapter(itemListDataAdapter);
    sectionDetailGamesScreenshotViewHolder.RecyclerViewDetailSectionGamesScreenshot.setNestedScrollingEnabled(false);
}

@Override
public int getItemCount() {
    int itemCount = modelDetailSectionGamesScreenshots.size();
    return itemCount;
}

public class SectionDetailGamesScreenshotViewHolder extends RecyclerView.ViewHolder {

    protected TextView TVSectionTitle;
    protected ImageView BTNDetailGamesScreenshot;
    protected RecyclerView RecyclerViewDetailSectionGamesScreenshot;

    public SectionDetailGamesScreenshotViewHolder(View itemView) {
        super(itemView);

        TVSectionTitle = (TextView) itemView.findViewById(R.id.TV_SectionTitle);
        BTNDetailGamesScreenshot = (ImageView) itemView.findViewById(R.id.BTNDetail_GamesScreenshot);
        RecyclerViewDetailSectionGamesScreenshot = (RecyclerView) itemView.findViewById(R.id.RecyclerViewDetail_Section_GamesScreenshot);

    }

}

}

// Адаптер Single

public class AdapterDetailSingleGamesScreenshot extends RecyclerView.Adapter{

private Context mContext;
private ArrayList<ModelDetailSingleGamesScreenshot> modelDetailSingleGamesScreenshots;

public AdapterDetailSingleGamesScreenshot(Context mContext, ArrayList<ModelDetailSingleGamesScreenshot> modelDetailSingleGamesScreenshots) {
    this.mContext = mContext;
    this.modelDetailSingleGamesScreenshots = modelDetailSingleGamesScreenshots;
}

//Container
@Override
public SingleDetailGamesScreenshotViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.itemdetail_single_gamesscreenshot, null);
    return new SingleDetailGamesScreenshotViewHolder(v);
}

//Fill Container with Model Setter Getter
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

    final SingleDetailGamesScreenshotViewHolder singleDetailGamesScreenshotViewHolder = (SingleDetailGamesScreenshotViewHolder) holder;
    final ModelDetailSingleGamesScreenshot modelDetailSingleGamesScreenshotX = modelDetailSingleGamesScreenshots.get(position);

    //Set
    singleDetailGamesScreenshotViewHolder.IMGGameImage.setImageResource(modelDetailSingleGamesScreenshotX.getGameimage());


   /* Glide.with(mContext)
            .load(feedItem.getImageURL())
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .centerCrop()
            .error(R.drawable.bg)
            .into(feedListRowHolder.thumbView);*/


    singleDetailGamesScreenshotViewHolder.ROWDetailGamesScreenshotContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(v.getContext(), modelDetailSingleGamesScreenshots.get(position).getGameimage(), Toast.LENGTH_SHORT).show();
        }
    });
}

@Override
public int getItemCount() {
    int itemCount = modelDetailSingleGamesScreenshots.size();
    return itemCount;
}

public class SingleDetailGamesScreenshotViewHolder extends RecyclerView.ViewHolder{
    ImageView IMGGameImage;

    private RelativeLayout ROWDetailGamesScreenshotContainer;


    public SingleDetailGamesScreenshotViewHolder(View itemView) {
        super(itemView);
        IMGGameImage = itemView.findViewById(R.id.IMG_GameImage);

        ROWDetailGamesScreenshotContainer = itemView.findViewById(R.id.ROW_DetailGamesScreenshotContainer);
    }

}


}

// Секция Model

public class ModelDetailSectionGamesScreenshot implements Serializable {

private String headerTitle;
private ArrayList<ModelDetailSingleGamesScreenshot> allItemsInSection;

public ModelDetailSectionGamesScreenshot() {
}

public String getHeaderTitle() {
    return headerTitle;
}

public void setHeaderTitle(String headerTitle) {
    this.headerTitle = headerTitle;
}

public ArrayList<ModelDetailSingleGamesScreenshot> getAllItemsInSection() {
    return allItemsInSection;
}

public void setAllItemsInSection(ArrayList<ModelDetailSingleGamesScreenshot> allItemsInSection) {
    this.allItemsInSection = allItemsInSection;
}


}

// ModelSingle // аааааааааааааааааааааааааааааааааааааааааааааааааааа1023 *

public class ModelDetailSingleGamesScreenshot implements Serializable {

private int id;
private int gameimage;


public ModelDetailSingleGamesScreenshot(int id, int gameimage) {
    this.id = id;
    this.gameimage = gameimage;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public int getGameimage() {
    return gameimage;
}

public void setGameimage(int gameimage) {
    this.gameimage = gameimage;
}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...