mirror of
https://github.com/afollestad/nock-nock.git
synced 2025-08-17 15:59:51 +00:00
Some more logic updates and fixes
This commit is contained in:
parent
c508c36930
commit
7a728d8754
5 changed files with 33 additions and 6 deletions
|
@ -6,6 +6,7 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.afollestad.nocknock.R;
|
import com.afollestad.nocknock.R;
|
||||||
import com.afollestad.nocknock.api.ServerModel;
|
import com.afollestad.nocknock.api.ServerModel;
|
||||||
|
@ -117,7 +118,7 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.ServerVH>
|
||||||
return mServers.size();
|
return mServers.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ServerVH extends RecyclerView.ViewHolder {
|
public static class ServerVH extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
|
||||||
final ImageView iconStatus;
|
final ImageView iconStatus;
|
||||||
final TextView textName;
|
final TextView textName;
|
||||||
|
@ -132,6 +133,13 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.ServerVH>
|
||||||
textInterval = (TextView) itemView.findViewById(R.id.textInterval);
|
textInterval = (TextView) itemView.findViewById(R.id.textInterval);
|
||||||
textUrl = (TextView) itemView.findViewById(R.id.textUrl);
|
textUrl = (TextView) itemView.findViewById(R.id.textUrl);
|
||||||
textStatus = (TextView) itemView.findViewById(R.id.textStatus);
|
textStatus = (TextView) itemView.findViewById(R.id.textStatus);
|
||||||
|
|
||||||
|
itemView.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Toast.makeText(view.getContext(), "Coming soon", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,6 @@ public class AddSiteActivity extends AppCompatActivity implements View.OnClickLi
|
||||||
ServerModel model = new ServerModel();
|
ServerModel model = new ServerModel();
|
||||||
model.name = inputName.getText().toString().trim();
|
model.name = inputName.getText().toString().trim();
|
||||||
model.url = inputUrl.getText().toString().trim();
|
model.url = inputUrl.getText().toString().trim();
|
||||||
model.lastCheck = -1;
|
|
||||||
model.status = ServerStatus.WAITING;
|
model.status = ServerStatus.WAITING;
|
||||||
|
|
||||||
String intervalStr = inputInterval.getText().toString().trim();
|
String intervalStr = inputInterval.getText().toString().trim();
|
||||||
|
@ -143,6 +142,8 @@ public class AddSiteActivity extends AppCompatActivity implements View.OnClickLi
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model.lastCheck = System.currentTimeMillis() - model.checkInterval;
|
||||||
|
|
||||||
setResult(RESULT_OK, new Intent()
|
setResult(RESULT_OK, new Intent()
|
||||||
.putExtra("model", model));
|
.putExtra("model", model));
|
||||||
finish();
|
finish();
|
||||||
|
|
|
@ -34,6 +34,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||||
private RecyclerView mList;
|
private RecyclerView mList;
|
||||||
private ServerAdapter mAdapter;
|
private ServerAdapter mAdapter;
|
||||||
private TextView mEmptyText;
|
private TextView mEmptyText;
|
||||||
|
private SwipeRefreshLayout mRefreshLayout;
|
||||||
|
|
||||||
private ObjectAnimator mFabAnimator;
|
private ObjectAnimator mFabAnimator;
|
||||||
private float mOrigFabX;
|
private float mOrigFabX;
|
||||||
|
@ -51,9 +52,9 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||||
mList.setAdapter(mAdapter);
|
mList.setAdapter(mAdapter);
|
||||||
|
|
||||||
SwipeRefreshLayout sr = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
|
mRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
|
||||||
sr.setOnRefreshListener(this);
|
mRefreshLayout.setOnRefreshListener(this);
|
||||||
sr.setColorSchemeColors(ContextCompat.getColor(this, R.color.md_green),
|
mRefreshLayout.setColorSchemeColors(ContextCompat.getColor(this, R.color.md_green),
|
||||||
ContextCompat.getColor(this, R.color.md_yellow),
|
ContextCompat.getColor(this, R.color.md_yellow),
|
||||||
ContextCompat.getColor(this, R.color.md_red));
|
ContextCompat.getColor(this, R.color.md_red));
|
||||||
|
|
||||||
|
@ -61,9 +62,19 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||||
mFab.setOnClickListener(this);
|
mFab.setOnClickListener(this);
|
||||||
|
|
||||||
Inquiry.init(this, "nocknock", 1);
|
Inquiry.init(this, "nocknock", 1);
|
||||||
|
refreshModels();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshModels() {
|
||||||
|
mEmptyText.setVisibility(View.GONE);
|
||||||
Inquiry.get()
|
Inquiry.get()
|
||||||
.selectFrom(SITES_TABLE_NAME, ServerModel.class)
|
.selectFrom(SITES_TABLE_NAME, ServerModel.class)
|
||||||
.all(result -> mAdapter.set(result));
|
.all(this::setModels);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setModels(ServerModel[] models) {
|
||||||
|
mAdapter.set(models);
|
||||||
|
mEmptyText.setVisibility(mAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,6 +101,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
|
mRefreshLayout.setRefreshing(false);
|
||||||
// TODO check all servers in order
|
// TODO check all servers in order
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,6 +140,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
ServerModel model = (ServerModel) data.getSerializableExtra("model");
|
ServerModel model = (ServerModel) data.getSerializableExtra("model");
|
||||||
mAdapter.add(model);
|
mAdapter.add(model);
|
||||||
|
mEmptyText.setVisibility(View.GONE);
|
||||||
|
|
||||||
Inquiry.get().insertInto(SITES_TABLE_NAME, ServerModel.class)
|
Inquiry.get().insertInto(SITES_TABLE_NAME, ServerModel.class)
|
||||||
.values(model)
|
.values(model)
|
||||||
|
|
|
@ -40,7 +40,9 @@
|
||||||
android:id="@+id/inputName"
|
android:id="@+id/inputName"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="sans-serif-light"
|
||||||
android:hint="@string/site_name"
|
android:hint="@string/site_name"
|
||||||
|
android:inputType="textPersonName"
|
||||||
android:textColor="?android:textColorPrimary"
|
android:textColor="?android:textColorPrimary"
|
||||||
android:textColorHint="?android:textColorSecondary" />
|
android:textColorHint="?android:textColorSecondary" />
|
||||||
|
|
||||||
|
@ -57,7 +59,9 @@
|
||||||
android:id="@+id/inputUrl"
|
android:id="@+id/inputUrl"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="sans-serif-light"
|
||||||
android:hint="@string/site_url"
|
android:hint="@string/site_url"
|
||||||
|
android:inputType="textUri"
|
||||||
android:textColor="?android:textColorPrimary"
|
android:textColor="?android:textColorPrimary"
|
||||||
android:textColorHint="?android:textColorSecondary" />
|
android:textColorHint="?android:textColorSecondary" />
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?selectableItemBackground"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingLeft="@dimen/content_inset"
|
android:paddingLeft="@dimen/content_inset"
|
||||||
android:paddingRight="@dimen/content_inset">
|
android:paddingRight="@dimen/content_inset">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue