基线备份:thirdparty 变体完成 + Android 4.2 兼容改造前
包含内容: - thirdparty flavor 独立 applicationId + Intent 入口(ThirdPartyEntryActivity) - 58 后端接口适配(单 /api 路径、code 0/200、camelCase 字段、UNBOUND 轮询) - MAC 硬件锚定校验(防一凭证多设备共用) - EPG mac 覆盖 SDK init(sMacOverride)+ ChannelManger 初始化对齐 - 提示文案优化(设备未注册/权益未绑定)
This commit is contained in:
26
app/src/androidTest/java/com/migu/jiecheng/ExampleInstrumentedTest.java
Executable file
26
app/src/androidTest/java/com/migu/jiecheng/ExampleInstrumentedTest.java
Executable file
@@ -0,0 +1,26 @@
|
||||
package com.migu.jiecheng;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.migu.jiecheng", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
199
app/src/androidTest/java/com/migu/jiecheng/IndexNavType6TestActivity.java
Executable file
199
app/src/androidTest/java/com/migu/jiecheng/IndexNavType6TestActivity.java
Executable file
@@ -0,0 +1,199 @@
|
||||
package com.migu.jiecheng;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
public class IndexNavType6TestActivity extends AppCompatActivity {
|
||||
private RecyclerView recyclerView;
|
||||
private TabLayout tabLayout;
|
||||
private TestAdapter adapter;
|
||||
private boolean isProgrammaticSelection;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
LinearLayout root = new LinearLayout(this);
|
||||
root.setOrientation(LinearLayout.VERTICAL);
|
||||
root.setLayoutParams(new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
));
|
||||
|
||||
Button externalButton = new Button(this);
|
||||
externalButton.setId(android.R.id.button1);
|
||||
externalButton.setText("切换 navtype=6");
|
||||
root.addView(externalButton, new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
));
|
||||
|
||||
tabLayout = new TabLayout(this);
|
||||
tabLayout.setId(android.R.id.tabs);
|
||||
root.addView(tabLayout, new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
));
|
||||
|
||||
recyclerView = new RecyclerView(this);
|
||||
recyclerView.setId(android.R.id.list);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
|
||||
adapter = new TestAdapter();
|
||||
recyclerView.setAdapter(adapter);
|
||||
root.addView(recyclerView, new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
));
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
tabLayout.addTab(tabLayout.newTab().setText("Tab " + i));
|
||||
}
|
||||
|
||||
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
if (tab != null) {
|
||||
IndexNavType6TestActivity.this.onTabSelected(tab.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
}
|
||||
});
|
||||
|
||||
externalButton.setOnClickListener(v -> onNavTypeChanged(6));
|
||||
setContentView(root);
|
||||
}
|
||||
|
||||
private void onNavTypeChanged(int navType) {
|
||||
if (isProgrammaticSelection) {
|
||||
return;
|
||||
}
|
||||
if (navType != 6) {
|
||||
return;
|
||||
}
|
||||
isProgrammaticSelection = true;
|
||||
try {
|
||||
syncSelection(6);
|
||||
} finally {
|
||||
isProgrammaticSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void onTabSelected(int targetPosition) {
|
||||
if (isProgrammaticSelection) {
|
||||
return;
|
||||
}
|
||||
isProgrammaticSelection = true;
|
||||
try {
|
||||
syncSelection(targetPosition);
|
||||
} finally {
|
||||
isProgrammaticSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void syncSelection(int targetPosition) {
|
||||
recyclerView.scrollToPosition(targetPosition);
|
||||
adapter.setSelectedPosition(targetPosition);
|
||||
TabLayout.Tab tab = tabLayout.getTabAt(targetPosition);
|
||||
if (tab != null) {
|
||||
tab.select();
|
||||
}
|
||||
}
|
||||
|
||||
public int getSelectedPosition() {
|
||||
return adapter.getSelectedPosition();
|
||||
}
|
||||
|
||||
public int getSelectedTabPosition() {
|
||||
return tabLayout.getSelectedTabPosition();
|
||||
}
|
||||
|
||||
public int getNotifyItemChangedCount() {
|
||||
return adapter.getNotifyItemChangedCount();
|
||||
}
|
||||
|
||||
private static class TestAdapter extends RecyclerView.Adapter<TestAdapter.Holder> {
|
||||
private int selectedPosition = RecyclerView.NO_POSITION;
|
||||
private int notifyItemChangedCount = 0;
|
||||
|
||||
void setSelectedPosition(int position) {
|
||||
if (position < 0 || position >= getItemCount()) {
|
||||
return;
|
||||
}
|
||||
if (selectedPosition == position) {
|
||||
notifyItemChanged(position);
|
||||
notifyItemChangedCount++;
|
||||
return;
|
||||
}
|
||||
int oldPosition = selectedPosition;
|
||||
selectedPosition = position;
|
||||
if (oldPosition != RecyclerView.NO_POSITION) {
|
||||
notifyItemChanged(oldPosition);
|
||||
notifyItemChangedCount++;
|
||||
}
|
||||
notifyItemChanged(selectedPosition);
|
||||
notifyItemChangedCount++;
|
||||
}
|
||||
|
||||
int getSelectedPosition() {
|
||||
return selectedPosition;
|
||||
}
|
||||
|
||||
int getNotifyItemChangedCount() {
|
||||
return notifyItemChangedCount;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
TextView textView = new TextView(parent.getContext());
|
||||
textView.setGravity(Gravity.CENTER);
|
||||
textView.setPadding(24, 24, 24, 24);
|
||||
return new Holder(textView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull Holder holder, int position) {
|
||||
holder.textView.setText(String.valueOf(position));
|
||||
boolean selected = position == selectedPosition;
|
||||
holder.textView.setBackgroundColor(selected ? Color.parseColor("#FF4CAF50") : Color.parseColor("#00000000"));
|
||||
holder.textView.setTextColor(selected ? Color.parseColor("#FFFFFFFF") : Color.parseColor("#FF999999"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
static class Holder extends RecyclerView.ViewHolder {
|
||||
private final TextView textView;
|
||||
|
||||
Holder(@NonNull TextView itemView) {
|
||||
super(itemView);
|
||||
this.textView = itemView;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
app/src/androidTest/java/com/migu/jiecheng/IndexNavType6UiTest.java
Executable file
33
app/src/androidTest/java/com/migu/jiecheng/IndexNavType6UiTest.java
Executable file
@@ -0,0 +1,33 @@
|
||||
package com.migu.jiecheng;
|
||||
|
||||
import androidx.test.core.app.ActivityScenario;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.LargeTest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@LargeTest
|
||||
public class IndexNavType6UiTest {
|
||||
|
||||
@Test
|
||||
public void 点击外部按钮切换到navtype6后列表与Tab应同步高亮() {
|
||||
try (ActivityScenario<IndexNavType6TestActivity> scenario =
|
||||
ActivityScenario.launch(IndexNavType6TestActivity.class)) {
|
||||
onView(withId(android.R.id.button1)).perform(click());
|
||||
|
||||
scenario.onActivity(activity -> {
|
||||
assertEquals(6, activity.getSelectedPosition());
|
||||
assertEquals(6, activity.getSelectedTabPosition());
|
||||
assertTrue(activity.getNotifyItemChangedCount() <= 2);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user