Skip to content

Commit

Permalink
modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Benojir committed Sep 9, 2024
1 parent 0eb54b8 commit 0833ec3
Show file tree
Hide file tree
Showing 22 changed files with 418 additions and 412 deletions.
8 changes: 8 additions & 0 deletions .idea/deploymentTargetSelector.xml

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

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ android {
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.preference:preference:1.2.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
Expand Down
47 changes: 26 additions & 21 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
android:name="android.hardware.touchscreen"
android:required="false" />

<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" tools:node="remove"/>
<uses-permission
android:name="android.permission.ACCESS_WIFI_STATE"
tools:node="remove" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.VIBRATE" />
Expand All @@ -30,22 +32,26 @@
</queries>

<application
android:name=".others.ApplicationClass"
android:allowBackup="true"
android:banner="@drawable/tv_logo"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:preserveLegacyExternalStorage="true"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Base.Theme.Fogplix"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
android:preserveLegacyExternalStorage="true"
tools:targetApi="31"
android:name="com.fogplix.tv.others.ApplicationClass"
android:banner="@drawable/tv_logo">
tools:targetApi="31">
<activity
android:name=".activities.SettingsActivity"
android:exported="false"
android:label="@string/title_activity_settings" />

<provider
android:name="androidx.core.content.FileProvider"
Expand All @@ -58,46 +64,45 @@
</provider>

<activity
android:name="com.fogplix.tv.activities.FavoriteActivity"
android:exported="true"
android:configChanges="orientation|uiMode|screenSize|keyboardHidden">
android:name=".activities.FavoriteActivity"
android:configChanges="orientation|uiMode|screenSize|keyboardHidden"
android:exported="true">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name="com.fogplix.tv.activities.GenreViewActivity"
android:exported="false"
android:configChanges="orientation|uiMode|screenSize|keyboardHidden">
android:name=".activities.GenreViewActivity"
android:configChanges="orientation|uiMode|screenSize|keyboardHidden"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name="com.fogplix.tv.activities.SearchActivity"
android:name=".activities.SearchActivity"
android:configChanges="orientation|uiMode|screenSize|keyboardHidden"
android:exported="true">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name="com.fogplix.tv.activities.PlayerActivity"
android:name=".activities.PlayerActivity"
android:configChanges="orientation|uiMode|screenSize|keyboardHidden"
android:exported="false"
android:hardwareAccelerated="true"
android:screenOrientation="sensorLandscape">
</activity>
android:screenOrientation="sensorLandscape"></activity>
<activity
android:name="com.fogplix.tv.activities.DetailsActivity"
android:name=".activities.DetailsActivity"
android:configChanges="uiMode|orientation|screenSize"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name="com.fogplix.tv.activities.MainActivity"
android:name=".activities.MainActivity"
android:configChanges="orientation|uiMode|screenSize|keyboardHidden"
android:exported="true"
android:theme="@style/Theme.App.Starting">
Expand All @@ -110,8 +115,8 @@
<meta-data
android:name="android.app.lib_name"
android:value="" />

<meta-data android:name="android.app.shortcuts"
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
</application>
Expand Down
122 changes: 33 additions & 89 deletions app/src/main/java/com/fogplix/tv/activities/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.fogplix.tv.activities;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.ImageButton;
import android.widget.PopupMenu;
Expand All @@ -17,32 +14,24 @@
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.splashscreen.SplashScreen;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager2.widget.ViewPager2;

import com.fogplix.tv.BuildConfig;
import com.fogplix.tv.R;
import com.fogplix.tv.adapters.FragmentAdapter;
import com.fogplix.tv.helpers.CustomMethods;
import com.google.android.material.navigation.NavigationView;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;

import java.util.Objects;

public class MainActivity extends AppCompatActivity {

private DrawerLayout drawerLayout;
private ViewPager2 viewPager2;
private TabLayout tabLayout;
private TextView importantNoticeTV;
private NavigationView navigationView;
private boolean keepSplashScreen = true;
private boolean doubleBackPressed = false;

@SuppressLint("SetTextI18n")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -61,35 +50,55 @@ protected void onCreate(Bundle savedInstanceState) {

View ownToolbar = findViewById(R.id.ownToolbar);

ImageButton navLeftBtn = ownToolbar.findViewById(R.id.navbarLeftBtn);
ImageButton favoritePageBtn = ownToolbar.findViewById(R.id.navbarLeftBtn);
ImageButton searchBtn = ownToolbar.findViewById(R.id.navbarRightBtn);
ImageButton navInfoBtn = ownToolbar.findViewById(R.id.navInfoBtn);

navLeftBtn.setImageDrawable(AppCompatResources.getDrawable(MainActivity.this, R.drawable.favorite_48));
navLeftBtn.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, FavoriteActivity.class)));
favoritePageBtn.setImageDrawable(AppCompatResources.getDrawable(MainActivity.this, R.drawable.favorite_48));
favoritePageBtn.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, FavoriteActivity.class)));
favoritePageBtn.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus){
favoritePageBtn.setBackgroundResource(R.drawable.button_focused);
} else {
favoritePageBtn.setBackgroundResource(R.drawable.button_default);
}
});

ownToolbar.findViewById(R.id.navbarRightBtn).setOnClickListener(v -> startActivity(new Intent(MainActivity.this, SearchActivity.class)));
searchBtn.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, SearchActivity.class)));
searchBtn.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus){
searchBtn.setBackgroundResource(R.drawable.button_focused);
} else {
searchBtn.setBackgroundResource(R.drawable.button_default);
}
});

ImageButton navInfoBtn = ownToolbar.findViewById(R.id.navInfoBtn);

navInfoBtn.setOnClickListener(v -> {

PopupMenu popupMenu = new PopupMenu(MainActivity.this, navInfoBtn);
popupMenu.getMenuInflater().inflate(R.menu.top_right_popup_menu, popupMenu.getMenu());

// Set up the click listener for the menu items
popupMenu.setOnMenuItemClickListener(item -> {

if (item.getItemId() == R.id.show_version){
if (item.getItemId() == R.id.open_settings){
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
return true;
} else if (item.getItemId() == R.id.show_version){
Toast.makeText(this, BuildConfig.VERSION_NAME, Toast.LENGTH_SHORT).show();
return true;
} else {
return false;
}
});

// Show the popup menu
popupMenu.show();
});

navInfoBtn.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus){
navInfoBtn.setBackgroundResource(R.drawable.button_focused);
} else {
navInfoBtn.setBackgroundResource(R.drawable.button_default);
}
});

////////////////////////////////////////////////////////////////////////////////////////////

CustomMethods.checkForUpdateOnStartApp(this);
Expand All @@ -98,22 +107,11 @@ protected void onCreate(Bundle savedInstanceState) {

if (!CustomMethods.isInternetOn(this)) {
Toast.makeText(this, "No internet connection.", Toast.LENGTH_LONG).show();
doubleBackPressed = true;
onBackPressed();
finish();
}

////////////////////////////////////////////////////////////////////////////////////////////

View headView = navigationView.getHeaderView(0);

((TextView) headView.findViewById(R.id.header_layout_version_tv)).setText("Version: " + BuildConfig.VERSION_NAME);

headView.findViewById(R.id.closeDrawerBtn).setOnClickListener(v -> drawerLayout.closeDrawers());

navigationViewItemClickedActions(navigationView);

////////////////////////////////////////////////////////////////////////////////////////////

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentAdapter fragmentAdapter = new FragmentAdapter(fragmentManager, getLifecycle(), tabLayout.getTabCount());
viewPager2.setAdapter(fragmentAdapter);
Expand Down Expand Up @@ -149,65 +147,11 @@ public void onPageSelected(int position) {
});
}


// ----------------------------------------------------------------------------------------------

private void navigationViewItemClickedActions(NavigationView navigationView) {

navigationView.setNavigationItemSelectedListener(item -> {

if (item.getItemId() == R.id.favorite_anime_menu_item) {

startActivity(new Intent(getApplicationContext(), FavoriteActivity.class));

new Handler().postDelayed(() -> {
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START);
}
}, 500);
} else if (item.getItemId() == R.id.report_bug_action) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.official_telegram_group))));
} else if (item.getItemId() == R.id.share_action) {
Intent intent1 = new Intent(Intent.ACTION_SEND);
intent1.setType("text/plain");
intent1.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.app_sharing_message) + "\n" + getString(R.string.official_website));
startActivity(Intent.createChooser(intent1, "Share via"));
} else if (item.getItemId() == R.id.more_apps_action) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.more_apps))));
} else if (item.getItemId() == R.id.visit_website) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.official_website))));
} else if (item.getItemId() == R.id.visit_telegram) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.official_telegram_channel))));
}
return false;
});
}

// ----------------------------------------------------------------------------------------------

@Override
public void onBackPressed() {

if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START);
} else {
if (doubleBackPressed) {
super.onBackPressed();
} else {
this.doubleBackPressed = true;
Snackbar.make(drawerLayout, "Double press to exit!", Snackbar.LENGTH_LONG).show();

new Handler(Looper.getMainLooper()).postDelayed(() -> doubleBackPressed = false, 2000);
}
}
}
// ----------------------------------------------------------------------------------------------

private void initVars() {
drawerLayout = findViewById(R.id.home_page_drawerlayout);
viewPager2 = findViewById(R.id.fragmentContainerViewPager2Main);
tabLayout = findViewById(R.id.tabLayout);
navigationView = findViewById(R.id.navigation_drawer);
importantNoticeTV = findViewById(R.id.important_notice_tv);
}
}
39 changes: 39 additions & 0 deletions app/src/main/java/com/fogplix/tv/activities/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.fogplix.tv.activities;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceFragmentCompat;

import com.fogplix.tv.R;

public class SettingsActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, new SettingsFragment())
.commit();
}
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
}

findViewById(R.id.backButton).setOnClickListener(v -> onBackPressed());
}

public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);
}
}
}
Loading

0 comments on commit 0833ec3

Please sign in to comment.