Skip to content

Commit

Permalink
准备模组下载
Browse files Browse the repository at this point in the history
  • Loading branch information
Tungstend committed May 13, 2022
1 parent fb515e8 commit 5f2a80e
Show file tree
Hide file tree
Showing 23 changed files with 478 additions and 206 deletions.
1 change: 1 addition & 0 deletions .idea/misc.xml

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

28 changes: 14 additions & 14 deletions HMCLPE/src/main/java/com/tungsten/hmclpe/launcher/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.afollestad.appthemeengine.ATE;
Expand Down Expand Up @@ -55,6 +56,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
public ImageButton backToDesktop;
public ImageButton closeApp;

public RelativeLayout uiContainer;
public UIManager uiManager;

public Config exteriorConfig;
Expand All @@ -79,23 +81,20 @@ private void init(){
}
}
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
new Thread(){
@Override
public void run(){
AppManifest.initializeManifest(MainActivity.this);
launcherSetting = InitializeSetting.initializeLauncherSetting();
publicGameSetting = InitializeSetting.initializePublicGameSetting(MainActivity.this,MainActivity.this);
privateGameSetting = InitializeSetting.initializePrivateGameSetting(MainActivity.this);
new Thread(() -> {
AppManifest.initializeManifest(MainActivity.this);
launcherSetting = InitializeSetting.initializeLauncherSetting();
publicGameSetting = InitializeSetting.initializePublicGameSetting(MainActivity.this,MainActivity.this);
privateGameSetting = InitializeSetting.initializePrivateGameSetting(MainActivity.this);

runOnUiThread(() -> {
updateChecker = new UpdateChecker(MainActivity.this,MainActivity.this);
});
runOnUiThread(() -> {
updateChecker = new UpdateChecker(MainActivity.this,MainActivity.this);
});

DownloadUrlSource.getBalancedSource(MainActivity.this);
DownloadUrlSource.getBalancedSource(MainActivity.this);

loadingHandler.sendEmptyMessage(0);
}
}.start();
loadingHandler.sendEmptyMessage(0);
}).start();
}

@SuppressLint("HandlerLeak")
Expand All @@ -122,6 +121,7 @@ public void handleMessage(@NonNull Message msg) {
backToDesktop.setOnClickListener(MainActivity.this);
closeApp.setOnClickListener(MainActivity.this);

uiContainer = findViewById(R.id.main_ui_container);
uiManager = new UIManager(MainActivity.this,MainActivity.this);

exteriorConfig.primaryColor(Color.parseColor(ExteriorSettingUI.getThemeColor(MainActivity.this,launcherSetting.launcherTheme)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.tungsten.hmclpe.R;

public class ExitActivity extends AppCompatActivity {

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -17,21 +15,18 @@
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import com.tungsten.hmclpe.R;
import com.tungsten.hmclpe.launcher.MainActivity;
import com.tungsten.hmclpe.launcher.mod.ModInfo;
import com.tungsten.hmclpe.launcher.mod.ModListBean;
import com.tungsten.hmclpe.launcher.uis.game.download.right.resource.DownloadResourceUI;
import com.tungsten.hmclpe.utils.string.ModTranslations;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class DownloadModListAdapter extends BaseAdapter {

Expand Down Expand Up @@ -69,7 +64,6 @@ public long getItemId(int position) {
}

@SuppressLint("UseCompatLoadingForDrawables")
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
Expand All @@ -89,48 +83,31 @@ public View getView(int position, View convertView, ViewGroup parent) {
}
viewHolder.modIcon.setImageDrawable(context.getDrawable(R.drawable.launcher_background_color_white));
viewHolder.modIcon.setTag(position);
new Thread(){
@Override
public void run() {
try {
URL url = new URL(modList.get(position).getIconUrl());
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
Bitmap icon = BitmapFactory.decodeStream(inputStream);
if (viewHolder.modIcon.getTag().equals(position)){
handler.post(new Runnable() {
@Override
public void run() {
viewHolder.modIcon.setImageBitmap(icon);
}
});
}
} catch (IOException e) {
e.printStackTrace();
new Thread(() -> {
try {
URL url = new URL(modList.get(position).getIconUrl());
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
Bitmap icon = BitmapFactory.decodeStream(inputStream);
if (viewHolder.modIcon.getTag().equals(position)){
handler.post(() -> viewHolder.modIcon.setImageBitmap(icon));
}
} catch (IOException e) {
e.printStackTrace();
}
}.start();
}).start();
String categories = "";
for (int i = 0;i < modList.get(position).getCategories().size();i++){
//categories = categories + SearchTools.getCategoryFromID(context,modList.get(position).getCategories().get(i)) + " ";
}
viewHolder.modCategories.setText(categories);
viewHolder.modName.setText(ModTranslations.getDisplayName(modList.get(position).getTitle(),modList.get(position).getSlug()));
viewHolder.modIntroduction.setText(modList.get(position).getDescription());
viewHolder.modItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(()->{
try {
ModInfo modInfo=new ModInfo(modList.get(position));
Log.e("mod",modInfo.toString());
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
viewHolder.modItem.setOnClickListener(view -> {
DownloadResourceUI downloadResourceUI = new DownloadResourceUI(context,activity,modList.get(position));
activity.uiManager.switchMainUI(downloadResourceUI);
});
return convertView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,41 +81,35 @@ public View getView(int position, View convertView, ViewGroup parent) {
}
viewHolder.packageIcon.setImageDrawable(context.getDrawable(R.drawable.launcher_background_color_white));
viewHolder.packageIcon.setTag(position);
new Thread(){
@Override
public void run() {
try {
URL url = new URL(packageList.get(position).getIconUrl());
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
Bitmap icon = BitmapFactory.decodeStream(inputStream);
if (viewHolder.packageIcon.getTag().equals(position)){
handler.post(new Runnable() {
@Override
public void run() {
viewHolder.packageIcon.setImageBitmap(icon);
}
});
}
} catch (IOException e) {
e.printStackTrace();
new Thread(() -> {
try {
URL url = new URL(packageList.get(position).getIconUrl());
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
Bitmap icon = BitmapFactory.decodeStream(inputStream);
if (viewHolder.packageIcon.getTag().equals(position)){
handler.post(new Runnable() {
@Override
public void run() {
viewHolder.packageIcon.setImageBitmap(icon);
}
});
}
} catch (IOException e) {
e.printStackTrace();
}
}.start();
}).start();
String categories = "";
for (int i = 0;i < packageList.get(position).getCategories().size();i++){
//categories = categories + SearchTools.getCategoryFromID(context,worldList.get(position).getCategories().get(i)) + " ";
}
viewHolder.packageCategories.setText(categories);
viewHolder.packageName.setText(packageList.get(position).getTitle());
viewHolder.packageIntroduction.setText(packageList.get(position).getDescription());
viewHolder.packageItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
viewHolder.packageItem.setOnClickListener(v -> {

}
});
return convertView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,41 +81,35 @@ public View getView(int position, View convertView, ViewGroup parent) {
}
viewHolder.resourcePackIcon.setImageDrawable(context.getDrawable(R.drawable.launcher_background_color_white));
viewHolder.resourcePackIcon.setTag(position);
new Thread(){
@Override
public void run() {
try {
URL url = new URL(resourcePackList.get(position).getIconUrl());
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
Bitmap icon = BitmapFactory.decodeStream(inputStream);
if (viewHolder.resourcePackIcon.getTag().equals(position)){
handler.post(new Runnable() {
@Override
public void run() {
viewHolder.resourcePackIcon.setImageBitmap(icon);
}
});
}
} catch (IOException e) {
e.printStackTrace();
new Thread(() -> {
try {
URL url = new URL(resourcePackList.get(position).getIconUrl());
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
Bitmap icon = BitmapFactory.decodeStream(inputStream);
if (viewHolder.resourcePackIcon.getTag().equals(position)){
handler.post(new Runnable() {
@Override
public void run() {
viewHolder.resourcePackIcon.setImageBitmap(icon);
}
});
}
} catch (IOException e) {
e.printStackTrace();
}
}.start();
}).start();
String categories = "";
for (int i = 0;i < resourcePackList.get(position).getCategories().size();i++){
//categories = categories + SearchTools.getCategoryFromID(context,worldList.get(position).getCategories().get(i)) + " ";
}
viewHolder.resourcePackCategories.setText(categories);
viewHolder.resourcePackName.setText(resourcePackList.get(position).getTitle());
viewHolder.resourcePackIntroduction.setText(resourcePackList.get(position).getDescription());
viewHolder.resourcePackItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
viewHolder.resourcePackItem.setOnClickListener(v -> {

}
});
return convertView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,41 +81,35 @@ public View getView(int position, View convertView, ViewGroup parent) {
}
viewHolder.worldIcon.setImageDrawable(context.getDrawable(R.drawable.launcher_background_color_white));
viewHolder.worldIcon.setTag(position);
new Thread(){
@Override
public void run() {
try {
URL url = new URL(worldList.get(position).getIconUrl());
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
Bitmap icon = BitmapFactory.decodeStream(inputStream);
if (viewHolder.worldIcon.getTag().equals(position)){
handler.post(new Runnable() {
@Override
public void run() {
viewHolder.worldIcon.setImageBitmap(icon);
}
});
}
} catch (IOException e) {
e.printStackTrace();
new Thread(() -> {
try {
URL url = new URL(worldList.get(position).getIconUrl());
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
Bitmap icon = BitmapFactory.decodeStream(inputStream);
if (viewHolder.worldIcon.getTag().equals(position)){
handler.post(new Runnable() {
@Override
public void run() {
viewHolder.worldIcon.setImageBitmap(icon);
}
});
}
} catch (IOException e) {
e.printStackTrace();
}
}.start();
}).start();
String categories = "";
for (int i = 0;i < worldList.get(position).getCategories().size();i++){
//categories = categories + SearchTools.getCategoryFromID(context,worldList.get(position).getCategories().get(i)) + " ";
}
viewHolder.worldCategories.setText(categories);
viewHolder.worldName.setText(worldList.get(position).getTitle());
viewHolder.worldIntroduction.setText(worldList.get(position).getDescription());
viewHolder.worldItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
viewHolder.worldItem.setOnClickListener(v -> {

}
});
return convertView;
}
Expand Down
Loading

0 comments on commit 5f2a80e

Please sign in to comment.