diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index e8931c1..0c0c338 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -3,20 +3,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index c2911c4..8fc0fec 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -11,6 +11,7 @@
+
+
+
+
+
+
{
+ if (status != TextToSpeech.ERROR) {
+ textToSpeech.setLanguage(Locale.US);
+ }
+ });
+
ImageView imageView = findViewById(R.id.anime_image);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
@@ -146,6 +155,16 @@ public void onLoadCleared(@Nullable Drawable placeholder) {
});
TextView descriptionTextView = findViewById(R.id.anime_description);
+ descriptionTextView.setOnClickListener(v -> {
+ if (textToSpeech.isSpeaking()) {
+ textToSpeech.stop();
+ } else {
+ String description = descriptionTextView.getText().toString();
+ textToSpeech.setLanguage(Locale.US);
+ textToSpeech.speak(description, TextToSpeech.QUEUE_FLUSH, null, null);
+ }
+ });
+
TextView scoreTextView = findViewById(R.id.anime_score);
scoreTextView.setOnClickListener(new View.OnClickListener() {
@Override
@@ -180,6 +199,15 @@ public void onClick(View v) {
TextView durationTextView = findViewById(R.id.anime_duration);
TextView popularityTextView = findViewById(R.id.anime_popularity);
TextView titleNativeTextView = findViewById(R.id.anime_title_native);
+ titleNativeTextView.setOnClickListener(v -> {
+ if (textToSpeech.isSpeaking()) {
+ textToSpeech.stop();
+ } else {
+ String titleNative = titleNativeTextView.getText().toString();
+ textToSpeech.setLanguage(Locale.JAPANESE);
+ textToSpeech.speak(titleNative, TextToSpeech.QUEUE_FLUSH, null, null);
+ }
+ });
TextView seasonTextView = findViewById(R.id.anime_season);
TextView statusTextView = findViewById(R.id.anime_status);
TextView typeTextView = findViewById(R.id.anime_type);
@@ -276,6 +304,11 @@ private void fetchMusicVideos(int id) {
handler.post(() -> {
Toast.makeText(this, "Failed to fetch music videos", Toast.LENGTH_SHORT).show();
});
+ } catch (Exception e) {
+ e.printStackTrace();
+ handler.post(() -> {
+ Toast.makeText(this, "Failed to fetch music videos", Toast.LENGTH_SHORT).show();
+ });
}
});
}
@@ -382,4 +415,13 @@ private int getBroadcastDay(String broadcastDay) {
return -1; // Invalid broadcast day
}
}
+
+ @Override
+ protected void onDestroy() {
+ if (textToSpeech != null) {
+ textToSpeech.stop();
+ textToSpeech.shutdown();
+ }
+ super.onDestroy();
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/luka/anidroid/activity/MainActivity.java b/app/src/main/java/com/luka/anidroid/activity/MainActivity.java
index 5d4207c..b6fb0ce 100644
--- a/app/src/main/java/com/luka/anidroid/activity/MainActivity.java
+++ b/app/src/main/java/com/luka/anidroid/activity/MainActivity.java
@@ -1,10 +1,12 @@
package com.luka.anidroid.activity;
+import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
+import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
@@ -30,16 +32,12 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- // Save the state of your activity or any data you want to retain
- // For example, you can save the selected item id of the BottomNavigationView
outState.putInt("selectedItemId", bottomNavigationView.getSelectedItemId());
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
- // Restore the saved state of your activity or any data
- // For example, you can restore the selected item id of the BottomNavigationView
int selectedItemId = savedInstanceState.getInt("selectedItemId");
bottomNavigationView.setSelectedItemId(selectedItemId);
}
@@ -55,12 +53,22 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
// Set HomeFragment as default fragment
- getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit();
+ getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, favoritesFragment).commit();
bottomNavigationView = findViewById(R.id.bottom_navigation);
// Set home item as selected
- bottomNavigationView.setSelectedItemId(R.id.navigation_home);
+ bottomNavigationView.setSelectedItemId(R.id.navigation_favorites);
+
+ Intent intent = getIntent();
+ String action = intent.getAction();
+ String type = intent.getType();
+
+ if (Intent.ACTION_SEND.equals(action) && type != null) {
+ if ("text/plain".equals(type)) {
+ handleSendText(intent); // Handle text being sent
+ }
+ }
bottomNavigationView.setOnItemSelectedListener(item -> {
Fragment selectedFragment = null;
@@ -114,6 +122,18 @@ public void onSensorChanged(SensorEvent event) {
}
}
+ void handleSendText(Intent intent) {
+ String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
+ if (sharedText != null) {
+
+ getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, searchFragment).commit();
+ bottomNavigationView.setSelectedItemId(R.id.action_search);
+ EditText searchEditText = findViewById(R.id.search_view);
+
+ searchFragment.searchAnime(sharedText);
+ }
+ }
+
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
diff --git a/app/src/main/java/com/luka/anidroid/fragment/HomeFragment.java b/app/src/main/java/com/luka/anidroid/fragment/HomeFragment.java
index a613154..da16bef 100644
--- a/app/src/main/java/com/luka/anidroid/fragment/HomeFragment.java
+++ b/app/src/main/java/com/luka/anidroid/fragment/HomeFragment.java
@@ -112,6 +112,8 @@ private void fetchAnimeData(List animeList, int page) {
jsonArray = new JSONArray(data.toString());
} catch (JSONException e) {
throw new RuntimeException(e);
+ } catch (NullPointerException e) {
+ return;
}
for (int i = 0; i < jsonArray.length(); i++) {
diff --git a/app/src/main/java/com/luka/anidroid/fragment/SearchFragment.java b/app/src/main/java/com/luka/anidroid/fragment/SearchFragment.java
index ec91cdb..efd1adf 100644
--- a/app/src/main/java/com/luka/anidroid/fragment/SearchFragment.java
+++ b/app/src/main/java/com/luka/anidroid/fragment/SearchFragment.java
@@ -83,7 +83,7 @@ public boolean onQueryTextChange(String newText) {
return view;
}
- private void searchAnime(String query) {
+ public void searchAnime(String query) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Handler handler = new Handler(Looper.getMainLooper());
@@ -111,6 +111,8 @@ private void searchAnime(String query) {
jsonArray = new JSONArray(data.toString());
} catch (JSONException e) {
throw new RuntimeException(e);
+ } catch (NullPointerException e) {
+ return;
}
for (int i = 0; i < jsonArray.length(); i++) {