feat: Повышение стабильности приложения, обновление зависимостей и доработка интерфейса

Этот коммит включает ряд улучшений по всему приложению:

Стабильность:
- Реализована null-безопасность для getArguments() в ChatListFragment, чтобы предотвратить NullPointerException.
- Устранено предупреждение о непроверенном приведении типов в ChatListFragment с использованием @SuppressWarnings("unchecked").
- Обеспечено корректное управление ресурсами: объект Response в VkApiClient обёрнут в try-with-resources для предотвращения утечек ресурсов.

Управление зависимостями:
- Проект обновлён до Java 17 для повышения производительности и использования современных возможностей языка.
- Все прямые объявления зависимостей перенесены в Gradle Version Catalog (libs.versions.toml) для лучшей организации и упрощённого управления внешними библиотеками.

Пользовательский интерфейс:
- Улучшено визуальное отображение ViewPager2 в activity_main.xml путём добавления горизонтальных отступов для более сбалансированного макета.
- В MultiLinkDialog заменён LayoutInflater.from(requireContext()) на getLayoutInflater() для лучшего соответствия жизненному циклу Fragment.
This commit is contained in:
2026-01-17 22:51:58 +03:00
parent 56c5100557
commit 098828d8d5
7 changed files with 45 additions and 46 deletions

View File

@@ -12,8 +12,8 @@ android {
applicationId "com.anabasis.vkchatmanager"
minSdk 26
targetSdk 36
versionCode 2
versionName "1.1"
versionCode 3
versionName "1.1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
@@ -25,17 +25,17 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}
dependencies {
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'androidx.viewpager2:viewpager2:1.1.0'
implementation "com.google.android.material:material:1.12.0"
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'org.json:json:20240303'
implementation libs.recyclerview
implementation libs.viewpager2
implementation libs.material
implementation libs.swiperefreshlayout
implementation libs.okhttp
implementation libs.json
}

View File

@@ -42,10 +42,13 @@ public class ChatListFragment extends Fragment {
@Override
@SuppressWarnings("unchecked")
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
chats = (ArrayList<VkChat>)
getArguments().getSerializable(ARG_CHATS);
Bundle arguments = getArguments();
if (arguments != null) {
chats = (ArrayList<VkChat>) arguments.getSerializable(ARG_CHATS);
}
if (chats == null) chats = new ArrayList<>();
}
@@ -90,11 +93,4 @@ public class ChatListFragment extends Fragment {
if (c.selected) res.add(c);
return res;
}
public void updateChats() {
if (adapter != null) {
adapter.notifyDataSetChanged();
}
}
}
}

View File

@@ -2,7 +2,6 @@ package com.anabasis.vkchatmanager.dialogs;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
@@ -33,7 +32,7 @@ public class MultiLinkDialog extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_multilink, null);
View view = getLayoutInflater().inflate(R.layout.dialog_multilink, null);
EditText input = view.findViewById(R.id.linksInput);
return new MaterialAlertDialogBuilder(requireContext())

View File

@@ -23,20 +23,21 @@ public class VkApiClient {
"&v=5.131";
Request r = new Request.Builder().url(url).build();
Response res = client.newCall(r).execute();
String body = res.body().string();
JSONObject json = new JSONObject(body);
try (Response res = client.newCall(r).execute()) {
if (json.has("error")) {
JSONObject error = json.getJSONObject("error");
if (error.getInt("error_code") == 5) {
throw new TokenExpiredException();
String body = res.body().string();
JSONObject json = new JSONObject(body);
if (json.has("error")) {
JSONObject error = json.getJSONObject("error");
if (error.getInt("error_code") == 5) {
throw new TokenExpiredException();
}
throw new Exception(error.getString("error_msg"));
}
throw new Exception(error.getString("error_msg"));
}
return json;
return json;
}
}
public JSONArray getChats() throws Exception {
@@ -83,4 +84,4 @@ public class VkApiClient {
return u.getString("first_name") + " " + u.getString("last_name");
}
}
}

View File

@@ -121,7 +121,9 @@
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:paddingStart="16dp"
android:paddingEnd="16dp" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
</RelativeLayout>