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