Skip to content

Commit

Permalink
Remove view binding, update dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Iscle <[email protected]>
  • Loading branch information
iscle committed Jul 22, 2021
1 parent b8bb6bc commit 35e1bd8
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 179 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 3 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ android {
defaultConfig {
applicationId "com.aof.mcinabox"
minSdkVersion 21
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 22
versionCode 8
versionName '0.1.4-p5'
}

buildFeatures {
viewBinding true
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -37,18 +34,11 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.github.MasayukiSuda:BubbleLayout:v1.2.1'
Expand All @@ -61,7 +51,7 @@ dependencies {
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'com.google.guava:guava:30.0-android'
implementation project(path: ':boat')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@

import androidx.appcompat.app.AppCompatActivity;

import com.aof.mcinabox.databinding.ActivityLoginBinding;
import com.aof.mcinabox.R;

public class LoginActivity extends AppCompatActivity {

private ActivityLoginBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityLoginBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setContentView(R.layout.activity_login);
}
}
10 changes: 5 additions & 5 deletions app/src/main/java/com/aof/mcinabox/activity/OldMainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Button;

import com.aof.mcinabox.databinding.ActivityOldMainBinding;
import com.aof.mcinabox.R;
import com.aof.mcinabox.gamecontroller.definitions.manifest.AppManifest;
import com.aof.mcinabox.launcher.lang.LangManager;
import com.aof.mcinabox.launcher.setting.SettingManager;
Expand All @@ -34,7 +35,6 @@ public class OldMainActivity extends BaseActivity {
public TipperManager mTipperManager;
public SettingManager mSettingManager;
public ThemeManager mThemeManager;
private ActivityOldMainBinding binding;
private static final int REFRESH_DELAY = 0; //ms
private static final int REFRESH_PERIOD = 1000; //ms
public static SettingJson Setting;
Expand All @@ -43,8 +43,7 @@ public class OldMainActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityOldMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setContentView(R.layout.activity_old_main);
//静态对象
CURRENT_ACTIVITY = new WeakReference<>(this);
//使用语言管理器切换语言
Expand Down Expand Up @@ -74,7 +73,8 @@ protected void onCreate(Bundle savedInstanceState) {
getWindow().setNavigationBarColor(Color.WHITE);
}

binding.layoutToolbarMain.toolbarButtonNewUi.setOnClickListener(v -> {
Button toolbarButtonNewUi = findViewById(R.id.toolbar_button_new_ui);
toolbarButtonNewUi.setOnClickListener(v -> {
Intent i = new Intent(OldMainActivity.this, MainActivity.class);
startActivity(i);
});
Expand Down
24 changes: 13 additions & 11 deletions app/src/main/java/com/aof/mcinabox/adapter/AccountAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.aof.mcinabox.MCinaBox;
import com.aof.mcinabox.databinding.AccountRowBinding;
import com.aof.mcinabox.R;
import com.aof.mcinabox.model.Account;
import com.aof.mcinabox.utils.SkinUtils;

Expand All @@ -25,20 +27,20 @@ public AccountAdapter(@NonNull MCinaBox mCinaBox, @NonNull Account[] accounts) {
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
final AccountRowBinding binding;

if (convertView == null) {
binding = AccountRowBinding.inflate(LayoutInflater.from(getContext()), parent, false);
} else {
binding = AccountRowBinding.bind(convertView);
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.account_row, parent, false);
}

final Account account = getItem(position);
binding.head.setImageBitmap(SkinUtils.getUserHead(mCinaBox, account.getName()));
binding.name.setText(account.getName());
binding.description.setText(account.getAccountType() == Account.Type.ONLINE ? "Online mode" : "Offline mode");
Account account = getItem(position);
ImageView head = convertView.findViewById(R.id.head);
TextView name = convertView.findViewById(R.id.name);
TextView description = convertView.findViewById(R.id.description);

head.setImageBitmap(SkinUtils.getUserHead(mCinaBox, account.getName()));
name.setText(account.getName());
description.setText(account.getAccountType() == Account.Type.ONLINE ? "Online mode" : "Offline mode");

return binding.getRoot();
return convertView;
}

@Override
Expand Down
23 changes: 12 additions & 11 deletions app/src/main/java/com/aof/mcinabox/adapter/VersionAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.aof.mcinabox.R;
import com.aof.mcinabox.databinding.VersionRowBinding;
import com.aof.mcinabox.model.Profile;

import java.util.List;
Expand All @@ -23,20 +24,20 @@ public VersionAdapter(@NonNull Context context, @NonNull List<Profile> profiles)
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
final VersionRowBinding binding;

if (convertView == null) {
binding = VersionRowBinding.inflate(LayoutInflater.from(getContext()), parent, false);
} else {
binding = VersionRowBinding.bind(convertView);
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.version_row, parent, false);
}

final Profile profile = getItem(position);
binding.icon.setImageResource(R.drawable.grass);
binding.name.setText(profile.getName());
binding.description.setText(profile.getDescription());
Profile profile = getItem(position);
ImageView icon = convertView.findViewById(R.id.icon);
TextView name = convertView.findViewById(R.id.name);
TextView description = convertView.findViewById(R.id.description);

icon.setImageResource(R.drawable.grass);
name.setText(profile.getName());
description.setText(profile.getDescription());

return binding.getRoot();
return convertView;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import android.content.Context;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;

import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.aof.mcinabox.databinding.FileChooserDialogBinding;
import com.aof.mcinabox.R;
import com.aof.mcinabox.filechooser.adapter.FileAdapter;
import com.aof.mcinabox.filechooser.model.ChooserFile;
import com.aof.mcinabox.filechooser.model.ChooserStackDirectory;
Expand All @@ -25,10 +27,12 @@ public class FileChooserDialog implements FileAdapter.OnClickListener {
private final LinkedList<ChooserStackDirectory> directoryStack;
private final String extension;
private final OnFileChosenListener listener;
private final FileChooserDialogBinding binding;
private final AlertDialog alertDialog;
private final FileAdapter fileAdapter;

private final View root;
private final RecyclerView recyclerView;

private FileChooserDialog(Context context, String title, String startPath, String extension, OnFileChosenListener listener) {
this.directoryStack = new LinkedList<>();
if (startPath != null) {
Expand All @@ -38,9 +42,12 @@ private FileChooserDialog(Context context, String title, String startPath, Strin
}
this.extension = extension;
this.listener = listener;
this.binding = FileChooserDialogBinding.inflate(LayoutInflater.from(context));
this.root = LayoutInflater.from(context).inflate(R.layout.file_chooser_dialog, null);
this.recyclerView = root.findViewById(R.id.recycler_view);


final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context)
.setView(binding.getRoot())
.setView(root)
.setNegativeButton("Cancel", null);
if (title == null) {
title = "Select a file";
Expand All @@ -53,9 +60,9 @@ private FileChooserDialog(Context context, String title, String startPath, Strin

this.fileAdapter = new FileAdapter(getFiles(), this);

binding.recyclerView.setAdapter(fileAdapter);
binding.recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
binding.recyclerView.addItemDecoration(new MarginItemDecoration());
recyclerView.setAdapter(fileAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
recyclerView.addItemDecoration(new MarginItemDecoration());
}

public void show() {
Expand Down Expand Up @@ -104,11 +111,11 @@ public void onClick(ChooserFile file) {
if ("..".equals(file.getName())) {
directoryStack.removeLast();
} else {
directoryStack.getLast().setOffset(binding.recyclerView.computeVerticalScrollOffset());
directoryStack.getLast().setOffset(recyclerView.computeVerticalScrollOffset());
directoryStack.addLast(new ChooserStackDirectory(file.getFile()));
}
fileAdapter.setFiles(getFiles());
binding.recyclerView.scrollBy(0, directoryStack.getLast().getOffset());
recyclerView.scrollBy(0, directoryStack.getLast().getOffset());
} else {
listener.onFileChosen(file.getFile());
dismiss();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.aof.mcinabox.R;
import com.aof.mcinabox.databinding.FileRowBinding;
import com.aof.mcinabox.filechooser.model.ChooserFile;

import java.util.List;
Expand All @@ -30,25 +31,26 @@ public FileAdapter(List<ChooserFile> files, OnClickListener listener) {
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
FileRowBinding binding = FileRowBinding
.inflate(LayoutInflater.from(parent.getContext()), parent, false);
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.file_row, parent, false);
ViewHolder holder = new ViewHolder(v);

switch (viewType) {
case TYPE_FILE:
binding.icon.setImageResource(R.drawable.ic_file);
binding.size.setVisibility(View.VISIBLE);
holder.icon.setImageResource(R.drawable.ic_file);
holder.size.setVisibility(View.VISIBLE);
break;
case TYPE_FOLDER:
binding.icon.setImageResource(R.drawable.ic_folder);
binding.size.setVisibility(View.GONE);
holder.icon.setImageResource(R.drawable.ic_folder);
holder.size.setVisibility(View.GONE);
break;
case TYPE_OPEN_FOLDER:
binding.icon.setImageResource(R.drawable.ic_folder_open);
binding.size.setVisibility(View.GONE);
holder.icon.setImageResource(R.drawable.ic_folder_open);
holder.size.setVisibility(View.GONE);
break;
}

return new ViewHolder(binding);
return holder;
}

@Override
Expand All @@ -70,8 +72,8 @@ public int getItemViewType(int position) {
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
ChooserFile f = files.get(position);

holder.binding.name.setText(f.getName());
holder.binding.size.setText(f.getSize());
holder.name.setText(f.getName());
holder.size.setText(f.getSize());
holder.itemView.setOnClickListener(v -> listener.onClick(f));
}

Expand All @@ -86,12 +88,15 @@ public void setFiles(List<ChooserFile> files) {
}

static class ViewHolder extends RecyclerView.ViewHolder {

private final FileRowBinding binding;

public ViewHolder(@NonNull FileRowBinding itemBinding) {
super(itemBinding.getRoot());
binding = itemBinding;
final TextView name;
final ImageView icon;
final TextView size;

public ViewHolder(@NonNull View itemView) {
super(itemView);
name = itemView.findViewById(R.id.name);
icon = itemView.findViewById(R.id.icon);
size = itemView.findViewById(R.id.size);
}
}

Expand Down
Loading

0 comments on commit 35e1bd8

Please sign in to comment.