mirror of
https://github.com/ChronosX88/Influence-P2P.git
synced 2024-11-21 15:02:17 +00:00
Made reconnect to the network without need restart app
This commit is contained in:
parent
1192ee3e9e
commit
6181665938
@ -61,7 +61,4 @@ dependencies {
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
configurations {
|
||||
all*.exclude group: 'com.google.guava', module:'listenablefuture'
|
||||
}
|
@ -54,7 +54,10 @@ interface CoreContracts {
|
||||
fun onDestroy()
|
||||
}
|
||||
|
||||
interface IMainViewContract//
|
||||
interface IMainViewContract {
|
||||
fun showSnackbar(message: String)
|
||||
fun showProgressBar(state: Boolean)
|
||||
}
|
||||
|
||||
// -----ChatActivity-----
|
||||
|
||||
|
@ -1,24 +0,0 @@
|
||||
package io.github.chronosx88.influence.presenters;
|
||||
|
||||
import io.github.chronosx88.influence.contracts.CoreContracts;
|
||||
import io.github.chronosx88.influence.logic.MainLogic;
|
||||
|
||||
public class MainPresenter implements CoreContracts.IMainPresenterContract {
|
||||
private CoreContracts.IMainLogicContract logic;
|
||||
private CoreContracts.IMainViewContract view;
|
||||
|
||||
public MainPresenter(CoreContracts.IMainViewContract view) {
|
||||
this.view = view;
|
||||
logic = new MainLogic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initPeer() {
|
||||
logic.initPeer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
logic.shutdownPeer();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package io.github.chronosx88.influence.presenters
|
||||
|
||||
import io.github.chronosx88.influence.R
|
||||
import io.github.chronosx88.influence.contracts.CoreContracts
|
||||
import io.github.chronosx88.influence.helpers.AppHelper
|
||||
import io.github.chronosx88.influence.logic.MainLogic
|
||||
|
||||
class MainPresenter(private val view: CoreContracts.IMainViewContract) : CoreContracts.IMainPresenterContract {
|
||||
private val logic: CoreContracts.IMainLogicContract = MainLogic()
|
||||
|
||||
override fun initPeer() {
|
||||
if (AppHelper.getPeerDHT() == null) {
|
||||
logic.initPeer()
|
||||
} else {
|
||||
view.showSnackbar(AppHelper.getContext().getString(R.string.node_already_running))
|
||||
view.showProgressBar(false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
logic.shutdownPeer()
|
||||
}
|
||||
}
|
@ -2,16 +2,23 @@ package io.github.chronosx88.influence.views;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import io.github.chronosx88.influence.R;
|
||||
import io.github.chronosx88.influence.contracts.CoreContracts;
|
||||
import io.github.chronosx88.influence.contracts.observer.IObserver;
|
||||
@ -130,4 +137,47 @@ public class MainActivity extends AppCompatActivity implements IObserver, CoreCo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main_actionbar_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if(item.getItemId() == R.id.action_reconnect_network) {
|
||||
progressDialog.show();
|
||||
presenter.initPeer();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showSnackbar(@NotNull String message) {
|
||||
Snackbar.make(getRootView(), message, Snackbar.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showProgressBar(boolean state) {
|
||||
if(state) {
|
||||
progressDialog.show();
|
||||
} else {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
private View getRootView() {
|
||||
final ViewGroup contentViewGroup = findViewById(android.R.id.content);
|
||||
View rootView = null;
|
||||
|
||||
if(contentViewGroup != null)
|
||||
rootView = contentViewGroup.getChildAt(0);
|
||||
|
||||
if(rootView == null)
|
||||
rootView = getWindow().getDecorView().getRootView();
|
||||
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
|
22
app/src/main/res/drawable/ic_autorenew_white_24dp.xml
Normal file
22
app/src/main/res/drawable/ic_autorenew_white_24dp.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<!--
|
||||
~ Copyright (C) 2019 ChronosX88
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M12,6v3l4,-4 -4,-4v3c-4.42,0 -8,3.58 -8,8 0,1.57 0.46,3.03 1.24,4.26L6.7,14.8c-0.45,-0.83 -0.7,-1.79 -0.7,-2.8 0,-3.31 2.69,-6 6,-6zM18.76,7.74L17.3,9.2c0.44,0.84 0.7,1.79 0.7,2.8 0,3.31 -2.69,6 -6,6v-3l-4,4 4,4v-3c4.42,0 8,-3.58 8,-8 0,-1.57 -0.46,-3.03 -1.24,-4.26z"/>
|
||||
</vector>
|
26
app/src/main/res/menu/main_actionbar_menu.xml
Normal file
26
app/src/main/res/menu/main_actionbar_menu.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2019 ChronosX88
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_reconnect_network"
|
||||
app:showAsAction="always"
|
||||
android:icon="@drawable/ic_autorenew_white_24dp"
|
||||
android:title="@string/reconnect_network"/>
|
||||
</menu>
|
@ -7,4 +7,6 @@
|
||||
<string name="cancel">Отмена</string>
|
||||
<string name="username_settings">Ваше имя пользователя</string>
|
||||
<string name="username_hint">Имя пользователя</string>
|
||||
<string name="reconnect_network">Переподключиться к сети</string>
|
||||
<string name="node_already_running">Узел уже запущен</string>
|
||||
</resources>
|
@ -6,4 +6,6 @@
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="username_settings">Your username</string>
|
||||
<string name="username_hint">Username</string>
|
||||
<string name="reconnect_network">Reconnect to the network</string>
|
||||
<string name="node_already_running">Node already running</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user