正在查看: Mint v5.7.3 应用的 ElectionCardTallyWidget.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Mint v5.7.3 应用的 ElectionCardTallyWidget.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.htmedia.mint.election.tally;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.datastore.preferences.core.settings.RemoteSettings;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.google.gson.Gson;
import com.htmedia.mint.AppController;
import com.htmedia.mint.R;
import com.htmedia.mint.election.pojo.tally.State;
import com.htmedia.mint.election.pojo.tally.TallyResponse;
import com.htmedia.mint.election.pojo.tally.TallyYearData;
import com.htmedia.mint.pojo.Content;
import com.htmedia.mint.pojo.config.Config;
import com.htmedia.mint.pojo.config.Election;
import com.htmedia.mint.pojo.config.Section;
import com.htmedia.mint.ui.fragments.HomeFragment;
import com.htmedia.mint.utils.f0;
import com.htmedia.mint.utils.n;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONObject;
import s8.c;
import x4.q7;
public class ElectionCardTallyWidget implements View.OnClickListener, c.s {
private final AppCompatActivity activity;
private q7 binding;
private Config config;
private final Content content;
private final Context context;
private c customJsonRequest;
private View indicesLayout;
private final LinearLayout layoutContainer;
private TabLayout tabLayout;
private TallyResponse tallyResponse;
private String URL = "https://www.hindustantimes.com/feed-elections/10s/2020-10/homebottomwidgets_wb.json";
private final Handler handler = new Handler();
public ElectionCardTallyWidget(LinearLayout linearLayout, AppCompatActivity appCompatActivity, Context context, Content content) {
this.layoutContainer = linearLayout;
this.activity = appCompatActivity;
this.context = context;
this.content = content;
}
private void callInitView() {
this.layoutContainer.removeAllViews();
View inflate = this.activity.getLayoutInflater().inflate(R.layout.card_election_layout, (ViewGroup) null);
this.indicesLayout = inflate;
q7 q7Var = (q7) DataBindingUtil.bind(inflate.getRootView());
this.binding = q7Var;
q7Var.c(Boolean.valueOf(AppController.j().E()));
if (AppController.j().E()) {
TabLayout tabLayout = this.binding.c;
this.tabLayout = tabLayout;
tabLayout.setVisibility(0);
this.binding.b.setVisibility(8);
} else {
q7 q7Var2 = this.binding;
this.tabLayout = q7Var2.b;
q7Var2.c.setVisibility(8);
this.binding.b.setVisibility(0);
}
setAdapterData();
setNightMode();
this.layoutContainer.addView(this.indicesLayout);
}
private ViewPagerTallyAdapter createCardAdapter() {
return new ViewPagerTallyAdapter(this.activity, this.tallyResponse.getStates(), this.tallyResponse.getSource(), this.tallyResponse.getTimestamp());
}
public void lambda$setAdapterData$0(TabLayout.Tab tab, int i) {
tab.setText(this.tallyResponse.getStates().get(i).getName());
}
private void openSectionOrChromeTab() {
Config config = this.config;
Election election = config != null ? config.getElection() : null;
if (this.context == null || election == null || !election.isWebViewEnable() || TextUtils.isEmpty(election.getWebViewUrl())) {
openSection();
} else {
f0.z2(this.context, f0.v(election.getWebViewUrl(), this.context));
}
}
private void setAdapterData() {
this.binding.f.setAdapter(createCardAdapter());
new TabLayoutMediator(this.tabLayout, this.binding.f, new TabLayoutMediator.TabConfigurationStrategy() {
public final void onConfigureTab(TabLayout.Tab tab, int i) {
ElectionCardTallyWidget.this.lambda$setAdapterData$0(tab, i);
}
}).attach();
}
public void getJsonFromServer(boolean z, String str, JSONObject jSONObject, String str2) {
ViewPager2 viewPager2;
if (!z || jSONObject == null) {
return;
}
TallyResponse tallyResponse = new TallyResponse();
Gson gson = new Gson();
try {
tallyResponse.setSource(jSONObject.getString("source"));
tallyResponse.setTimestamp(jSONObject.getString("timestamp"));
if (jSONObject.getJSONArray("states").length() > 0) {
ArrayList<State> arrayList = new ArrayList<>();
for (int i = 0; i < jSONObject.getJSONArray("states").length(); i++) {
State state = new State();
JSONObject jSONObject2 = jSONObject.getJSONArray("states").getJSONObject(i);
state.setName(jSONObject2.getString("name"));
state.setTallyYearPrevious((TallyYearData) gson.fromJson(jSONObject2.getJSONObject(this.config.getElection().firstYearKey).toString(), TallyYearData.class));
state.setTallyYearNext((TallyYearData) gson.fromJson(jSONObject2.getJSONObject(this.config.getElection().secondYearKey).toString(), TallyYearData.class));
arrayList.add(state);
}
tallyResponse.setStates(arrayList);
}
} catch (Exception e) {
e.printStackTrace();
}
if (tallyResponse.equals(this.tallyResponse)) {
return;
}
this.tallyResponse = tallyResponse;
q7 q7Var = this.binding;
if (q7Var == null || (viewPager2 = q7Var.f) == null || viewPager2.getAdapter() == null) {
callInitView();
} else {
setAdapterData();
}
}
public void init() {
Config g = AppController.j().g();
this.config = g;
if (g.getElection() == null || TextUtils.isEmpty(this.config.getElection().getTallyUrl())) {
return;
}
this.customJsonRequest = new c(this.context, this);
String tallyUrl = this.config.getElection().getTallyUrl();
this.URL = tallyUrl;
this.customJsonRequest.k(0, "Election", tallyUrl, (JSONObject) null, (HashMap) null, false, false);
scheduleSendLocation();
}
@Override
public void onClick(View view) {
if (view.getId() == 2131431053) {
openSectionOrChromeTab();
}
}
public void openSection() {
Parcelable section = new Section();
if (this.config.getElection().getFullCoverageUrl().contains("http")) {
section.setUrl(this.config.getElection().getFullCoverageUrl());
} else {
section.setUrl(RemoteSettings.FORWARD_SLASH_STRING + this.config.getElection().getFullCoverageUrl());
}
section.setDisplayName("Election");
section.setId("Section");
FragmentManager supportFragmentManager = this.context.getSupportFragmentManager();
HomeFragment homeFragment = new HomeFragment();
Bundle bundle = new Bundle();
bundle.putParcelable("top_section_section", section);
bundle.putBoolean("is_from_left_nav", true);
try {
bundle.putString(n.X, "Explore - " + section.getDisplayName());
} catch (Exception e) {
e.printStackTrace();
}
homeFragment.setArguments(bundle);
supportFragmentManager.beginTransaction().add(R.id.layoutFragmentContainer, homeFragment, "Tag_Section").addToBackStack("Tag_Section").commit();
this.context.f4(false, section.getDisplayName().toUpperCase());
}
public void scheduleSendLocation() {
this.handler.postDelayed(new Runnable() {
@Override
public void run() {
ElectionCardTallyWidget.this.customJsonRequest.k(0, "Election", ElectionCardTallyWidget.this.URL, (JSONObject) null, (HashMap) null, false, false);
ElectionCardTallyWidget.this.handler.postDelayed(this, 35000L);
}
}, 35000L);
}
public void setNightMode() {
this.binding.e.setText(this.config.getElection().getTallyWidgetTitle().replace("â\u0080\u0099", "'"));
if (TextUtils.isEmpty(this.config.getElection().getFullCoverageUrl()) || this.config.getElection().getCartograms().isEmpty()) {
this.binding.d.setVisibility(8);
} else {
this.binding.d.setOnClickListener(this);
this.binding.d.setVisibility(0);
}
if (AppController.j().E()) {
this.binding.a.setBackgroundColor(this.context.getResources().getColor(R.color.election_card_background_color_night));
this.binding.e.setTextColor(this.context.getResources().getColor(R.color.election_card_header_text_color_night));
} else {
this.binding.a.setBackgroundColor(ContextCompat.getColor(this.context, R.color.election_card_background_color));
this.binding.e.setTextColor(ContextCompat.getColor(this.context, R.color.election_card_header_text_color));
}
}
}