Skip to content

Commit

Permalink
Fixed dns test snackbar time
Browse files Browse the repository at this point in the history
  • Loading branch information
PeratX committed May 26, 2017
1 parent 07ae91b commit 0d88d6f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,8 @@
* (at your option) any later version.
*/
public class DnsServerConfigFragment extends ConfigFragment {
private View view;
private int index;

@Override
public void onDestroy() {
super.onDestroy();

view = null;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -46,7 +38,7 @@ public void onCreate(Bundle savedInstanceState) {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = super.onCreateView(inflater, container, savedInstanceState);
View view = super.onCreateView(inflater, container, savedInstanceState);

EditTextPreference serverName = (EditTextPreference) findPreference("serverName");
serverName.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
Expand Down Expand Up @@ -106,7 +98,7 @@ public boolean onMenuItemClick(MenuItem item) {
String serverPort = ((EditTextPreference) findPreference("serverPort")).getText();

if (serverName.equals("") | serverAddress.equals("") | serverPort.equals("")) {
Snackbar.make(view, R.string.notice_fill_in_all, Snackbar.LENGTH_LONG)
Snackbar.make(getView(), R.string.notice_fill_in_all, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private StringBuilder testServer(DNSQuery dnsQuery, String dnsServer, String tes
startTestBut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Snackbar.make(v, R.string.notice_start_test, Snackbar.LENGTH_LONG)
Snackbar.make(v, R.string.notice_start_test, Snackbar.LENGTH_SHORT)
.setAction("Action", null).show();
startTestBut.setVisibility(View.INVISIBLE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import android.os.Bundle;
import android.preference.*;
import android.support.design.widget.Snackbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R;
import org.itxtech.daedalus.util.DnsServerHelper;
Expand All @@ -25,7 +23,6 @@
* (at your option) any later version.
*/
public class GlobalConfigFragment extends PreferenceFragment {
private View view = null;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -46,7 +43,7 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary(DnsServerHelper.getDescription((String) newValue, Daedalus.getInstance()));
Snackbar.make(view, R.string.notice_need_restart, Snackbar.LENGTH_LONG)
Snackbar.make(getView(), R.string.notice_need_restart, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
return true;
}
Expand All @@ -60,7 +57,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary(DnsServerHelper.getDescription((String) newValue, Daedalus.getInstance()));
Snackbar.make(view, R.string.notice_need_restart, Snackbar.LENGTH_LONG)
Snackbar.make(getView(), R.string.notice_need_restart, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
return true;
}
Expand Down Expand Up @@ -121,12 +118,6 @@ public boolean onPreferenceClick(Preference preference) {
updateAdvancedOptions(advanced.isChecked());
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = super.onCreateView(inflater, container, savedInstanceState);
return view;
}

private void updateAdvancedOptions(boolean checked) {
PreferenceCategory category = (PreferenceCategory) findPreference("settings_advanced");
for (int i = 1; i < category.getPreferenceCount(); i++) {
Expand All @@ -143,18 +134,10 @@ private void updateAdvancedOptions(boolean checked) {
}

@Override
public void onStart() {
super.onStart();
if (view != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Snackbar.make(view, R.string.notice_legacy_api, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}

@Override
public void onDestroyView() {
super.onDestroyView();
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

view = null;
Snackbar.make(view, R.string.notice_legacy_api, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
13 changes: 2 additions & 11 deletions app/src/main/java/org/itxtech/daedalus/fragment/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
*/
public class MainFragment extends ToolbarFragment {

private View view = null;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_main, container, false);
View view = inflater.inflate(R.layout.fragment_main, container, false);

Button but = (Button) view.findViewById(R.id.button_activate);
but.setOnClickListener(new View.OnClickListener() {
Expand All @@ -50,13 +48,6 @@ public void checkStatus() {
toolbar.setTitle(R.string.action_home);
}

@Override
public void onDestroy() {
super.onDestroy();

view = null;
}

@Override
public void onResume() {
super.onResume();
Expand All @@ -65,7 +56,7 @@ public void onResume() {

private void updateUserInterface() {
Log.d("DMainFragment", "updateInterface");
Button but = (Button) view.findViewById(R.id.button_activate);
Button but = (Button) getView().findViewById(R.id.button_activate);
if (Daedalus.getInstance().isServiceActivated()) {
but.setText(R.string.button_text_deactivate);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class RuleConfigFragment extends ConfigFragment {
private Intent intent = null;
private Thread mThread = null;
private RuleConfigHandler mHandler = null;
private View view;
private int id;

public void setIntent(Intent intent) {
Expand All @@ -55,7 +54,6 @@ public void onDestroy() {
intent = null;
mHandler.shutdown();
mHandler = null;
view = null;
}

private void stopThread() {
Expand All @@ -74,7 +72,7 @@ public void onCreate(Bundle savedInstanceState) {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = super.onCreateView(inflater, container, savedInstanceState);
View view = super.onCreateView(inflater, container, savedInstanceState);

mHandler = new RuleConfigHandler().setView(view);

Expand Down Expand Up @@ -124,7 +122,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean onPreferenceClick(Preference preference) {
save();
if (mThread == null) {
Snackbar.make(view, R.string.notice_start_download, Snackbar.LENGTH_LONG)
Snackbar.make(getView(), R.string.notice_start_download, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
mThread = new Thread(new Runnable() {
@Override
Expand Down Expand Up @@ -152,7 +150,7 @@ public void run() {
});
mThread.start();
} else {
Snackbar.make(view, R.string.notice_now_downloading, Snackbar.LENGTH_LONG)
Snackbar.make(getView(), R.string.notice_now_downloading, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
return false;
Expand Down Expand Up @@ -214,7 +212,7 @@ private boolean save() {
String ruleDownloadUrl = ((EditTextPreference) findPreference("ruleDownloadUrl")).getText();

if (ruleName.equals("") | ruleType.equals("") | ruleFilename.equals("") | ruleDownloadUrl.equals("")) {
Snackbar.make(view, R.string.notice_fill_in_all, Snackbar.LENGTH_SHORT)
Snackbar.make(getView(), R.string.notice_fill_in_all, Snackbar.LENGTH_SHORT)
.setAction("Action", null).show();
return false;
}
Expand Down

0 comments on commit 0d88d6f

Please sign in to comment.