mirror of
https://github.com/ChronosX88/Influence-P2P.git
synced 2024-11-26 00:42:19 +00:00
Storing peerID and peerDHT in static class, showing peerID in settings
This commit is contained in:
parent
127bccd272
commit
64a527df78
@ -3,6 +3,8 @@ package io.github.chronosx88.influence.helpers;
|
|||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import net.tomp2p.dht.PeerDHT;
|
||||||
|
|
||||||
import io.github.chronosx88.influence.observable.MainObservable;
|
import io.github.chronosx88.influence.observable.MainObservable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,6 +14,8 @@ import io.github.chronosx88.influence.observable.MainObservable;
|
|||||||
public class AppHelper extends Application {
|
public class AppHelper extends Application {
|
||||||
private static Application instance;
|
private static Application instance;
|
||||||
private static MainObservable observable;
|
private static MainObservable observable;
|
||||||
|
private static String peerID;
|
||||||
|
private static PeerDHT peerDHT;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
@ -20,9 +24,17 @@ public class AppHelper extends Application {
|
|||||||
observable = new MainObservable();
|
observable = new MainObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void storePeerID(String peerID1) { peerID = peerID1; }
|
||||||
|
|
||||||
|
public static void storePeerDHT(PeerDHT peerDHT1) { peerDHT = peerDHT1; }
|
||||||
|
|
||||||
public static Context getContext() {
|
public static Context getContext() {
|
||||||
return instance.getApplicationContext();
|
return instance.getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MainObservable getObservable() { return observable; }
|
public static MainObservable getObservable() { return observable; }
|
||||||
|
|
||||||
|
public static String getPeerID() { return peerID; }
|
||||||
|
|
||||||
|
public static PeerDHT getPeerDHT() { return peerDHT; }
|
||||||
}
|
}
|
@ -8,7 +8,6 @@ import net.tomp2p.dht.PeerBuilderDHT;
|
|||||||
import net.tomp2p.dht.PeerDHT;
|
import net.tomp2p.dht.PeerDHT;
|
||||||
import net.tomp2p.futures.FutureBootstrap;
|
import net.tomp2p.futures.FutureBootstrap;
|
||||||
import net.tomp2p.futures.FutureDiscover;
|
import net.tomp2p.futures.FutureDiscover;
|
||||||
import net.tomp2p.nat.FutureNAT;
|
|
||||||
import net.tomp2p.nat.FutureRelayNAT;
|
import net.tomp2p.nat.FutureRelayNAT;
|
||||||
import net.tomp2p.nat.PeerBuilderNAT;
|
import net.tomp2p.nat.PeerBuilderNAT;
|
||||||
import net.tomp2p.nat.PeerNAT;
|
import net.tomp2p.nat.PeerNAT;
|
||||||
@ -24,8 +23,6 @@ import java.io.IOException;
|
|||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import io.github.chronosx88.influence.contracts.MainModelContract;
|
import io.github.chronosx88.influence.contracts.MainModelContract;
|
||||||
@ -131,6 +128,8 @@ public class MainModel implements MainModelContract {
|
|||||||
} catch (JSONException ex) {
|
} catch (JSONException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
AppHelper.storePeerID(preferences.getString("peerID", null));
|
||||||
|
AppHelper.storePeerDHT(peerDHT);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,28 @@
|
|||||||
package io.github.chronosx88.influence.views.fragments;
|
package io.github.chronosx88.influence.views.fragments;
|
||||||
|
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
import io.github.chronosx88.influence.R;
|
import io.github.chronosx88.influence.R;
|
||||||
|
import io.github.chronosx88.influence.helpers.AppHelper;
|
||||||
|
|
||||||
public class SettingsFragment extends PreferenceFragmentCompat {
|
public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle bundle, String s) {
|
public void onCreatePreferences(Bundle bundle, String s) {
|
||||||
setPreferencesFromResource(R.xml.main_settings, s);
|
// Load the Preferences from the XML file
|
||||||
|
addPreferencesFromResource(R.xml.main_settings);
|
||||||
|
getPreferenceScreen().getPreference(0).setSummary(AppHelper.getPeerID());
|
||||||
|
getPreferenceScreen().getPreference(0).setOnPreferenceClickListener((preference -> {
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) AppHelper.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
ClipData clip = ClipData.newPlainText("", AppHelper.getPeerID());
|
||||||
|
clipboard.setPrimaryClip(clip);
|
||||||
|
Toast.makeText(AppHelper.getContext(), "Скопировано в буфер обмена!", Toast.LENGTH_SHORT).show();
|
||||||
|
return false;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user