Created
March 18, 2021 18:45
-
-
Save amixpal/b7649be61c2b3ceaeba617b58674e827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fitme.app.activity.v2; | |
import android.os.Handler; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import androidx.recyclerview.widget.LinearLayoutManager; | |
import androidx.recyclerview.widget.RecyclerView; | |
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; | |
import com.bumptech.glide.Glide; | |
import com.fitme.app.R; | |
import com.fitme.app.activity.BaseActivity; | |
import com.fitme.app.adapter.AvailabilityAdapter; | |
import com.fitme.app.adapter.program.ProgramWeeklyPlanAdapter; | |
import com.fitme.app.entity.base.BaseObjectResponse; | |
import com.fitme.app.entity.model.program.IntroVideos; | |
import com.fitme.app.entity.model.program.PlanType; | |
import com.fitme.app.entity.model.program.ProgramLengthListItem; | |
import com.fitme.app.entity.model.program.ProgramModel; | |
import com.fitme.app.entity.model.program.PromoCodeInfo; | |
import com.fitme.app.entity.model.subscription.Loc; | |
import com.fitme.app.entity.model.subscription.MeetingLocation; | |
import com.fitme.app.entity.model.subscription.WeeklyPlanInfoItem; | |
import com.google.gson.Gson; | |
import com.google.gson.reflect.TypeToken; | |
import org.androidannotations.annotations.AfterViews; | |
import org.androidannotations.annotations.EActivity; | |
import org.androidannotations.annotations.ViewById; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.util.List; | |
@EActivity(R.layout.fragment_plan_details) | |
public class PlansDetailActivityInfo extends BaseActivity implements AvailabilityAdapter.AvailabilityListener { | |
private static final String TAG = "PlansFragment"; | |
@ViewById | |
SwipeRefreshLayout swipeLayout; | |
@ViewById | |
TextView title; | |
@ViewById | |
ImageView topImageView; | |
@ViewById | |
Button btnWatchVideo; | |
@ViewById | |
Button btnDiscount; | |
@ViewById | |
TextView tvSessionCount; | |
@ViewById | |
TextView tvIntensity; | |
@ViewById | |
TextView tvLevel; | |
@ViewById | |
View goodForView; | |
@ViewById | |
TextView tvGoodFor; | |
@ViewById | |
View equipmentView; | |
@ViewById | |
TextView tvEquipment; | |
@ViewById | |
View descriptionView; | |
@ViewById | |
TextView tvDescription; | |
@ViewById | |
View locationView; | |
@ViewById | |
ImageView locationImage; | |
@ViewById | |
TextView tvAddress; | |
@ViewById | |
View availabilityView; | |
@ViewById | |
RecyclerView availabilityRecyclerView; | |
@ViewById | |
View dietPlanView; | |
@ViewById | |
View includeSessionView; | |
@ViewById | |
RecyclerView includeSessionRecyclerView; | |
private AvailabilityAdapter availabilityAdapter; | |
ProgramWeeklyPlanAdapter programWeeklyPlanAdapter; | |
@AfterViews | |
public void afterViewCreated() { | |
setupAvailabilityRecyclerView(); | |
swipeLayout.setOnRefreshListener(this::refreshData); | |
} | |
private void refreshData() { | |
if (availabilityAdapter != null) { | |
availabilityAdapter.clear(); | |
} | |
if (programWeeklyPlanAdapter != null) { | |
programWeeklyPlanAdapter.clear(); | |
} | |
getDashBoardDetails(); | |
} | |
private void setupAvailabilityRecyclerView() { | |
availabilityAdapter = new AvailabilityAdapter(this); | |
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext(), RecyclerView.HORIZONTAL, false); | |
availabilityRecyclerView.setLayoutManager(linearLayoutManager); | |
availabilityRecyclerView.setNestedScrollingEnabled(false); | |
availabilityRecyclerView.setAdapter(availabilityAdapter); | |
} | |
@Override | |
public void onResume() { | |
super.onResume(); | |
getDashBoardDetails(); | |
} | |
public void getDashBoardDetails() { | |
fetchHomeData(); | |
} | |
private void fetchHomeData() { | |
try { | |
InputStream inputStream = getApplicationContext().getAssets().open("program_2.json"); | |
int size = inputStream.available(); | |
byte[] buffer = new byte[size]; | |
inputStream.read(buffer); | |
inputStream.close(); | |
String jsonStringData = new String(buffer); | |
BaseObjectResponse<ProgramModel> data = new Gson().fromJson(jsonStringData, new TypeToken<BaseObjectResponse<ProgramModel>>() { | |
}.getType()); | |
swipeLayout.setRefreshing(false); | |
if (data.isSuccess()) { | |
setupDataOnUI(data.getData()); | |
} else { | |
if (data.getError() != null) { | |
Toast.makeText(getApplicationContext(), data.getError(), Toast.LENGTH_SHORT).show(); | |
} else { | |
Toast.makeText(getApplicationContext(), "Something went wrong!!", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
} catch (IOException ex) { | |
ex.printStackTrace(); | |
} | |
} | |
private void setupDataOnUI(ProgramModel data) { | |
if (data != null) { | |
Glide.with(getApplicationContext()).load(data.getImageUrl()).into(topImageView); | |
title.setText(data.getName()); | |
tvSessionCount.setText(data.getNumberOfSessions() + ""); | |
List<String> workoutFocus = data.getWorkoutFocus(); | |
if (workoutFocus != null && !workoutFocus.isEmpty()) { | |
tvIntensity.setText(workoutFocus.get(0)); | |
} else { | |
tvIntensity.setText(""); | |
} | |
tvLevel.setText(data.getIntensityLevel()); | |
IntroVideos introVideos = data.getIntroVideos(); | |
watchVideoBtnVisibility(introVideos != null && introVideos.getVideo() != null); | |
PromoCodeInfo promoCodeInfo = data.getPromoCodeInfo(); | |
if (promoCodeInfo != null && promoCodeInfo.getCodeValue() != null) { | |
discountBtnVisibility(true); | |
btnDiscount.setText(promoCodeInfo.getCodeValue()); | |
} else { | |
discountBtnVisibility(false); | |
} | |
List<String> goodFor = data.getGoodFor(); | |
if (goodFor != null && !goodFor.isEmpty()) { | |
goodForViewVisibility(true); | |
tvGoodFor.setText(""); | |
for (String goodString : goodFor) { | |
tvGoodFor.append(goodString + ", "); | |
} | |
String string = tvGoodFor.getText().toString(); | |
tvGoodFor.setText(string.substring(0, string.length() - 2)); | |
} else { | |
goodForViewVisibility(false); | |
} | |
List<String> equipments = data.getEquipments(); | |
if (equipments != null && !equipments.isEmpty()) { | |
equipmentViewVisibility(true); | |
tvEquipment.setText(""); | |
for (String equipment : equipments) { | |
tvEquipment.append(equipment + ", "); | |
} | |
String string = tvEquipment.getText().toString(); | |
tvEquipment.setText(string.substring(0, string.length() - 2)); | |
} else { | |
equipmentViewVisibility(false); | |
} | |
String description = data.getDescription(); | |
if (description != null && !description.isEmpty()) { | |
descriptionViewVisibility(true); | |
tvDescription.setText(description); | |
} else { | |
descriptionViewVisibility(false); | |
} | |
MeetingLocation meetingLocation = data.getMeetingLocation(); | |
String meetingAddress = data.getMeetingAddress(); | |
if (meetingLocation != null && meetingAddress != null && !meetingAddress.isEmpty()) { | |
//Both are having values | |
locationViewVisibility(true); | |
tvAddress.setText(meetingAddress); | |
Loc loc = meetingLocation.getLoc(); | |
if (loc != null) { | |
List<Double> coordinates = loc.getCoordinates(); | |
String type = loc.getType(); | |
if (coordinates != null && coordinates.size() == 2) { | |
//Having Lat Lng | |
locationImage.setVisibility(View.VISIBLE); | |
String staticMapMakerUrl = createStaticMapMarker(coordinates, meetingAddress); | |
Glide.with(this).load(staticMapMakerUrl).into(locationImage); | |
} else { | |
//Not Having Lat Lng | |
locationImage.setVisibility(View.GONE); | |
} | |
} else { | |
locationImage.setVisibility(View.GONE); | |
} | |
} else if (meetingAddress != null && !meetingAddress.isEmpty()) { | |
//Meeting Location null but address not | |
locationViewVisibility(true); | |
locationImage.setVisibility(View.GONE); | |
tvAddress.setText(meetingAddress); | |
} else { | |
//Both are having null or address empty | |
locationViewVisibility(false); | |
} | |
List<ProgramLengthListItem> programLengthList = data.getProgramLengthList(); | |
if (programLengthList != null && !programLengthList.isEmpty()) { | |
availabilityViewVisibility(true); | |
availabilityAdapter.addAll(programLengthList); | |
} else { | |
availabilityViewVisibility(false); | |
} | |
PlanType planType = data.getPlanType(); | |
boolean ebook = false; | |
if (planType != null) { | |
ebook = planType.isEbook(); | |
} | |
dietPlanViewVisibility(ebook); | |
int programType = data.getProgramType(); // 1 - VideoInfo, 2 - No Recycler | |
if (programType == 2) { | |
//No Recycler | |
includeSessionVisibility(false); | |
} else if (programType == 0 || programType == 1) { | |
//0 - Training Info || 1 - Video Info | |
List<WeeklyPlanInfoItem> weeklyPlanInfo = data.getWeeklyPlanInfo(); | |
if (weeklyPlanInfo != null && !weeklyPlanInfo.isEmpty()) { | |
includeSessionVisibility(true); | |
int size = 0; | |
if (availabilityAdapter != null && availabilityAdapter.dataList.get(0) != null) { | |
size = availabilityAdapter.dataList.get(0).getTimeLineValue(); | |
} | |
programWeeklyPlanAdapter.addAll(weeklyPlanInfo); | |
programWeeklyPlanAdapter.setListSize(size); | |
programWeeklyPlanAdapter.notifyDataSetChanged(); | |
} else { | |
includeSessionVisibility(false); | |
} | |
} | |
} | |
} | |
private void watchVideoBtnVisibility(boolean isVisible) { | |
if (isVisible) { | |
btnWatchVideo.setVisibility(View.VISIBLE); | |
} else { | |
btnWatchVideo.setVisibility(View.GONE); | |
} | |
} | |
private void discountBtnVisibility(boolean isVisible) { | |
if (isVisible) { | |
btnDiscount.setVisibility(View.VISIBLE); | |
} else { | |
btnDiscount.setVisibility(View.GONE); | |
} | |
} | |
private void goodForViewVisibility(boolean isVisible) { | |
if (isVisible) { | |
goodForView.setVisibility(View.VISIBLE); | |
} else { | |
goodForView.setVisibility(View.GONE); | |
} | |
} | |
private String createStaticMapMarker(List<Double> coordinates, String meetingAddress) { | |
return "https://maps.googleapis.com/maps/api/staticmap?autoscale=1&size=640x640&maptype=roadmap&key=AIzaSyA3kg7YWugGl1lTXmAmaBGPNhDW9pEh5bo&format=png&visual_refresh=true&markers=size:mid%7Ccolor:0xff0000%7Clabel:C%7C" + coordinates.get(1) + "," + coordinates.get(0) + ""; | |
} | |
private void equipmentViewVisibility(boolean isVisible) { | |
if (isVisible) { | |
equipmentView.setVisibility(View.VISIBLE); | |
} else { | |
equipmentView.setVisibility(View.GONE); | |
} | |
} | |
private void descriptionViewVisibility(boolean isVisible) { | |
if (isVisible) { | |
descriptionView.setVisibility(View.VISIBLE); | |
} else { | |
descriptionView.setVisibility(View.GONE); | |
} | |
} | |
private void locationViewVisibility(boolean isVisible) { | |
if (isVisible) { | |
locationView.setVisibility(View.VISIBLE); | |
} else { | |
locationView.setVisibility(View.GONE); | |
} | |
} | |
private void availabilityViewVisibility(boolean isVisible) { | |
if (isVisible) { | |
availabilityView.setVisibility(View.VISIBLE); | |
setupAvailabilityRecyclerView(); | |
} else { | |
availabilityView.setVisibility(View.GONE); | |
} | |
} | |
private void dietPlanViewVisibility(boolean isVisible) { | |
if (isVisible) { | |
dietPlanView.setVisibility(View.VISIBLE); | |
} else { | |
dietPlanView.setVisibility(View.GONE); | |
} | |
} | |
private void includeSessionVisibility(boolean isVisible) { | |
if (isVisible) { | |
includeSessionView.setVisibility(View.VISIBLE); | |
setupIncludeSessionRecyclerView(); | |
} else { | |
includeSessionView.setVisibility(View.GONE); | |
} | |
} | |
private void setupIncludeSessionRecyclerView() { | |
programWeeklyPlanAdapter = new ProgramWeeklyPlanAdapter(); | |
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getApplicationContext(), RecyclerView.VERTICAL, false); | |
includeSessionRecyclerView.setLayoutManager(linearLayoutManager); | |
includeSessionRecyclerView.setNestedScrollingEnabled(false); | |
includeSessionRecyclerView.setAdapter(programWeeklyPlanAdapter); | |
} | |
@Override | |
public void onSelectAvailability(ProgramLengthListItem model, int position) { | |
if (programWeeklyPlanAdapter != null && programWeeklyPlanAdapter.dataList.size() > 0) { | |
// ((BaseActivity) getApplicationContext()).showProgress("Loading..."); | |
programWeeklyPlanAdapter.setListSize(model.getTimeLineValue()); | |
new Handler().postDelayed(() -> { | |
programWeeklyPlanAdapter.notifyDataSetChanged(); | |
// ((BaseActivity) getApplicationContext()).hideProgress(); | |
}, 2000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment