44import android .os .Bundle ;
55import android .support .annotation .Nullable ;
66import android .support .v7 .app .AppCompatActivity ;
7+ import android .support .v7 .widget .AppCompatImageView ;
8+ import android .text .Editable ;
9+ import android .text .Html ;
10+ import android .view .View ;
11+ import android .view .ViewGroup ;
12+ import android .widget .FrameLayout ;
713import android .widget .TextView ;
814import android .widget .Toast ;
915
16+ import com .squareup .picasso .Picasso ;
17+
18+ import org .xml .sax .XMLReader ;
19+
1020import butterknife .BindView ;
1121import butterknife .ButterKnife ;
22+ import butterknife .OnClick ;
1223import hamletleon .empleado_androidjava .R ;
24+ import hamletleon .empleado_androidjava .app .shared .IApiService ;
25+ import hamletleon .empleado_androidjava .infrastructure .api .ApiUtils ;
1326import hamletleon .empleado_androidjava .infrastructure .entities .Job ;
27+ import hamletleon .empleado_androidjava .infrastructure .entities .JobDetails ;
28+ import retrofit2 .Call ;
29+ import retrofit2 .Callback ;
30+ import retrofit2 .Response ;
31+
32+ import static hamletleon .empleado_androidjava .infrastructure .utils .tools .SendEmailIntent ;
1433
1534public class JobDetailsActivity extends AppCompatActivity {
35+ @ BindView (R .id .scrollView )
36+ View mScrollView ;
37+ @ BindView (R .id .progress )
38+ View mProgress ;
39+
40+ // Obsolete Design
41+ @ BindView (R .id .oldView )
42+ View mOldView ;
1643 @ BindView (R .id .jobTitle )
1744 TextView mJobTitle ;
1845 @ BindView (R .id .jobType )
@@ -26,39 +53,144 @@ public class JobDetailsActivity extends AppCompatActivity {
2653 @ BindView (R .id .jobDate )
2754 TextView mJobDate ;
2855
56+ // New Design
57+ @ BindView (R .id .newView )
58+ View mNewView ;
59+ @ BindView (R .id .companyLogo )
60+ AppCompatImageView mCompanyLogo ;
61+ @ BindView (R .id .companyName )
62+ TextView mCompanyName ;
63+ @ BindView (R .id .companyLocation )
64+ TextView mCompanyLocation ;
65+ @ BindView (R .id .companyWebsite )
66+ TextView mCompanyWebsite ;
67+ @ BindView (R .id .jobTitleNew )
68+ TextView mJobTitleNew ;
69+ @ BindView (R .id .jobCategoryNew )
70+ TextView mJobCategoryNew ;
71+ @ BindView (R .id .jobDetails )
72+ TextView mJobDetailsTextView ;
73+ @ BindView (R .id .jobContactEmail )
74+ TextView mJobContactEmail ;
75+
76+ private IApiService mApiService ;
77+ private Job mJob ;
78+ private JobDetails mJobDetails ;
79+
2980 @ Override
3081 protected void onCreate (@ Nullable Bundle savedInstanceState ) {
3182 super .onCreate (savedInstanceState );
3283 setContentView (R .layout .activity_job_details );
3384 ButterKnife .bind (this );
3485 Intent intent = getIntent ();
3586
36- Job mJob ;
3787 if (intent != null && intent .getExtras () != null && intent .getExtras ().containsKey (Job .class .getSimpleName ())) {
3888 mJob = intent .getExtras ().getParcelable (Job .class .getSimpleName ());
3989 if (mJob == null ) return ;
4090 } else {
4191 Toast .makeText (this , "FATAL ERROR!" , Toast .LENGTH_SHORT ).show ();
4292 return ;
4393 }
94+ mApiService = ApiUtils .getApiService ();
4495
4596 if (getSupportActionBar () != null ) {
4697 getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
4798 getSupportActionBar ().setDisplayShowHomeEnabled (true );
4899 }
49100 setTitle ("Detalles de puesto" );
50101
102+ if (mJob .JobURI != null ) {
103+ requestJobDetails (mJob .JobURI );
104+ } else {
105+ setOldView ();
106+ }
107+ }
108+
109+ private void setOldView () {
51110 mJobTitle .setText (mJob .jobTitle );
52111 mJobType .setText (mJob .jobType );
53112 mJobLocation .setText (mJob .jobLocation );
54113 mJobCompany .setText (mJob .jobCompany );
55114 mJobCategory .setText (mJob .jobCategory );
56115 mJobDate .setText (mJob .jobDate );
116+ mProgress .setVisibility (View .GONE );
117+ mOldView .setVisibility (View .VISIBLE );
118+ }
119+
120+ private void requestJobDetails (String jobUri ) {
121+ mApiService .getJobsDetails (jobUri .replaceFirst ("/" , "" )).enqueue (new Callback <JobDetails >() {
122+ @ Override
123+ public void onResponse (Call <JobDetails > call , Response <JobDetails > response ) {
124+ if (response .isSuccessful () && response .body () != null ) {
125+ mJobDetails = response .body ();
126+ setNewView ();
127+ } else {
128+ setOldView ();
129+ Toast .makeText (JobDetailsActivity .this , "Error: " + response .message (), Toast .LENGTH_SHORT ).show ();
130+ }
131+ }
132+
133+ @ Override
134+ public void onFailure (Call <JobDetails > call , Throwable t ) {
135+ setOldView ();
136+ Toast .makeText (JobDetailsActivity .this , "Error -> " + t .getMessage (), Toast .LENGTH_SHORT ).show ();
137+ }
138+ });
139+ }
140+
141+ private void setNewView () {
142+ mScrollView .setLayoutParams (new FrameLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT ));
143+
144+ if (mJobDetails .companyLogo != null ) {
145+ String imgUrl ;
146+ if (mJobDetails .companyLogo .contains ("http" ) || mJobDetails .companyLogo .contains ("www." ))
147+ imgUrl = mJobDetails .companyLogo .trim ();
148+ else imgUrl = "http://www.emplea.do" + mJobDetails .companyLogo .trim ();
149+ Picasso .with (JobDetailsActivity .this ).load (imgUrl ).into (mCompanyLogo );
150+ }
151+
152+ mCompanyName .setText (mJobDetails .companyName .trim ());
153+ mCompanyLocation .setText (mJobDetails .jobLocation .trim ());
154+
155+ if (mJobDetails .companyWebsite != null )
156+ mCompanyWebsite .setText (mJobDetails .companyWebsite .trim ());
157+ else mCompanyWebsite .setVisibility (View .GONE );
158+ if (mJobDetails .jobTitle != null )
159+ mJobTitleNew .setText (mJobDetails .jobTitle .trim ());
160+ else mJobTitleNew .setText (R .string .notSpecified );
161+ if (mJobDetails .jobCategory != null )
162+ mJobCategoryNew .setText (mJobDetails .jobCategory .trim ());
163+ else mJobCategoryNew .setText (R .string .notSpecified );
164+ if (mJobDetails .jobDetails != null )
165+ mJobDetailsTextView .setText (Html .fromHtml (mJobDetails .jobDetails .trim (), null , new UlTagHandler ()));
166+ else mJobDetailsTextView .setText (R .string .notSpecified );
167+ if (mJobDetails .jobContacEmail != null )
168+ mJobContactEmail .setText (String .format (getString (R .string .contactEmail ), mJobDetails .jobContacEmail .trim ()));
169+ else mJobContactEmail .setText (R .string .notContactEmail );
170+
171+ mProgress .setVisibility (View .GONE );
172+ mNewView .setVisibility (View .VISIBLE );
57173 }
58174
59175 @ Override
60176 public boolean onSupportNavigateUp () {
61177 onBackPressed ();
62178 return true ;
63179 }
180+
181+ @ OnClick (R .id .jobContactLayout )
182+ public void OnContactLayoutClicked () {
183+ SendEmailIntent (JobDetailsActivity .this , mJobDetails .jobContacEmail , "CV Puesto - " + mJobDetails .jobTitle ,
184+ "Saludos,\n Estoy interesado en el puesto de trabajo (" + mJobDetails .jobTitle + ")." +
185+ "\n \n Le adjunto mi CV para que evalue si soy un candidato pertinente para el puesto." +
186+ "\n \n Gracias anteladas por su atención.\n Que tenga buen resto del día." );
187+ }
188+
189+ public class UlTagHandler implements Html .TagHandler {
190+ @ Override
191+ public void handleTag (boolean opening , String tag , Editable output , XMLReader xmlReader ) {
192+ if (tag .equals ("ul" ) && !opening ) output .append ("\n " );
193+ if (tag .equals ("li" ) && opening ) output .append ("\n •\t " );
194+ }
195+ }
64196}
0 commit comments